Skip to content
Ralph Schaer edited this page Jul 10, 2012 · 3 revisions

How to setup ExtDirectSpring with Spring XML

ExtDirectSpring has to be embedded in a Spring MVC application. Spring MVC needs a dispatcher servlet, which is specified in web.xml

<servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/action/*</url-pattern>
</servlet-mapping>

With this configuration the corresponding Spring context file must be located in the same directory as web.xml and the name is action-servlet.xml. Another possibility is to specify the name and location of the file with the contextConfigLocation init parameter.

<servlet>
  <servlet-name>controller</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/META-INF/spring/controller/servlet-controller.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

Either way the Spring context file should look like this.

<?xml version="1.0" encoding="UTF-8"?>
<beans ...>

  <context:component-scan base-package="ch.ralscha.extdirectspring"/>         
  <mvc:annotation-driven />
  
  <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="100000"/>
  </bean>  

  ...
  
</beans>

The component-scan and annotation-driven tags are mandatory for ExtDirectSpring. The multipartResolver bean is only needed for file uploads and can be omitted.

On a Servlet 3.0 server it's possible to replace the CommonsMultipartResolver with the StandardServletMultipartResolver This resolver uses the multipart support in Servlet 3.0. To make it work it's also necessary to enable multipart support on the servlet.

<servlet>
  <servlet-name>controller</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
     ....
  </init-param>
  <load-on-startup>1</load-on-startup>
  <multipart-config />
</servlet>
Clone this wiki locally