7.3. Start-up Code — WebInitializer
Now we’ll get rid of the Web.xml file and create the WebInitializer class in its place:
package ru.ibase.fbjavaex.config;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletRegistration.Dynamic;import org.springframework.web.WebApplicationInitializer;import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;import org.springframework.web.servlet.DispatcherServlet;public class WebInitializer implements WebApplicationInitializer {@Overridepublic void onStartup(ServletContext servletContext) throws ServletException {AnnotationConfigWebApplicationContext ctx =new AnnotationConfigWebApplicationContext();ctx.register(WebAppConfig.class);ctx.setServletContext(servletContext);Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx));servlet.addMapping("/");servlet.setLoadOnStartup(1);}}
All that is left to configure is IoC containers for injecting dependencies, a step we will return to later. We proceed next to generating classes for working with the database via Java Object-Oriented Querying (jOOQ).
