Skip to content

Instantly share code, notes, and snippets.

Created January 22, 2018 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f4007272d6b47db2dceaa923732c9dde to your computer and use it in GitHub Desktop.
Save anonymous/f4007272d6b47db2dceaa923732c9dde to your computer and use it in GitHub Desktop.
package br.com.netsoft;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class SpringWebInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.scan(SpringWebInitializer.class.getPackage().getName());
servletContext.addListener(new ContextLoaderListener(applicationContext));
servletContext.addListener(new RequestContextListener());
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
dispatcherServlet(applicationContext));
dispatcher.setAsyncSupported(true);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
private DispatcherServlet dispatcherServlet(WebApplicationContext applicationContext) {
return new DispatcherServlet(applicationContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment