Skip to content

Config Spring Java Config

ralscha edited this page Oct 2, 2012 · 4 revisions

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)

In 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 (<multipart-config />). See XML Setup.

Clone this wiki locally