Created
June 18, 2011 17:49
-
-
Save anonymous/1033325 to your computer and use it in GitHub Desktop.
Java-based conatiner configuration with no web.xml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebAppInitializer implements WebApplicationInitializer { | |
public void onStartup(ServletContext container) throws ServletException { | |
// Create the 'root' Spring application context | |
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); | |
rootContext.register(RootContext.class); | |
// Manage the lifecycle of the root application context | |
container.addListener(new ContextLoaderListener(rootContext)); | |
// Create the dispatcher servlet's Spring application context | |
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); | |
dispatcherContext.register(mytld.mycompany.myapp.config.appServlet.ServletContext.class); | |
// Register and map the dispatcher servlet | |
ServletRegistration.Dynamic dispatcher = container.addServlet( | |
"appServlet", new DispatcherServlet(dispatcherContext)); | |
dispatcher.setLoadOnStartup(1); | |
dispatcher.addMapping("/main"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment