I’m using Spring MVC via a @Configuration class:
@Configuration
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
// more stuff
}
In my web.xml I create the ApplicationContext:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>my.package.WebConfiguration</param-value>
</context-param>
I also create a DispatcherServlet, as follows:
<servlet>
<servlet-name>mywebapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mywebapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
In order to get the dispatcherServlet to work I need a mywebapp-servlet.xml Right now, it’s empty. Do I actually need the mywebapp-servlet.xml file?
You don’t need any XML file. But you must tell the Dispatcher to not look for the default file:
Just for your information: in fact, in Servlet 3 web.xml is no longer required, too.