Spring Integration

Milton can be integrated with Spring in ways:

  1. Use MiltonController, a Spring MVC controller. You must use milton's slightly customized spring servlet DavEnabledDispatcherServlet, because spring's standard implementation forbids webdav methods
  2. Use SpringMiltonFilter. This will create a context, and will use org.springframework.web.context.ContextLoaderListener to connect to a parent context if one has been initialised
The second method is generally preferred. To use this approach setup the filter in web.xml as shown below, and setup your context xml file to create a bean named milton.http.manager which can be either a HttpManagerBuilder or a HttpManager

 

An example web.xml follows:
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:rootContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>openSessionInViewFilter</filter-name>
        <filter-class>
            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        </filter-class>
        <init-param>
            <param-name>singleSession</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>openSessionInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>        
    
    <filter>
        <filter-name>miltonFilter</filter-name>
        <filter-class>io.milton.servlet.SpringMiltonFilter</filter-class>
        <init-param>
            <param-name>milton.exclude.paths</param-name>    
            <param-value>/static,/templates</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>    
            <param-value>classpath:miltonContext.xml</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>miltonFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
        
</web-app>

And an example context xml file which uses the enterprise edition of milton:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


    <bean id="resource.factory" class="io.milton.http.annotated.AnnotationResourceFactory">
        <property name="controllers">
            <list>
                <bean class="com.bandstand.web.BandsController" />
                <bean class="com.bandstand.web.RootController" />
                <bean class="com.bandstand.web.MusiciansController" />
                <bean class="com.bandstand.web.ImagesController" />
                <bean class="com.bandstand.web.GigController" />
                <bean class="com.bandstand.web.BandMembersController" />
                <bean class="com.bandstand.web.ContactsController" />
                <bean class="com.bandstand.web.SongsController" />
            </list>
        </property>
        <property name="viewResolver">
            <bean class="io.milton.http.template.JspViewResolver">
                <constructor-arg ref="servletContext"/>
                <property name="theme" value="united" />
            </bean>
        </property>
    </bean>

    <bean id="milton.http.manager" class="io.milton.ent.config.HttpManagerBuilderEnt">
        <property name="mainResourceFactory" ref="resource.factory" />
        <property name="enableCompression" value="false"/>
        <property name="buffering" value="never"/>      
    </bean>    
</beans>