In a typical Spring MVC web app, you would declare the DispatcherServlet in web.xml like so
With JEE6, if your application container is Servlet 3.0 ready what you need to do is:
com.foo.FooServletContainer)META-INF/services folder named javax.servlet.ServletContainerInitializer which will contain the name of your implementation above (com.foo.FooServletContainer)Spring 3 is bundled with a class named SpringServletContainerInitializer that implements the stuff above (so you don't need to create yourself the file in META-INF/services. This class just calls an implementation of WebApplicationInitializer. So you just need to provide one class implementing it in your classpath (the following code is taken from the doc above).
public class FooInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) {
WebApplicationContext appContext = ...;
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new DispatcherServlet(appContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
That's it for the web.xml thing, but you need to configure the webapp using @Configuration, @EnableWebMvc etc..