1 Setting Up Spring Java
Ralph Schaer edited this page 2012-07-10 06:16:00 +02:00

How to setup ExtDirectSpring with Spring JavaConfig

A setup with JavaConfig still needs the DispatcherServlet described here.

The rest of the configuration is a translation of the XML Setup.

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "ch.ralscha.extdirectspring"}
public class WebConfig {

	@Bean
	public MultipartResolver multipartResolver() {
		CommonsMultipartResolver resolver = new CommonsMultipartResolver();
		resolver.setMaxUploadSize(100000);
		return resolver;
	}

    //some more configuration
}

The MultipartResolver is only needed for file uploads. The CommonsMultipartResolver needs two additional libraries (commons-fileupload and commons-io)

On a Servlet 3.0 container you could use the StandardServletMultipartResolver. The two libraries commons-fileupload and commons-io are no longer needed.

	@Bean
	public MultipartResolver multipartResolver() {
		return new StandardServletMultipartResolver();
	}

If you use this configuration don't forget to enable multipart support on the DispatcherServlet ({{{}}}). See XML Setup.