List of usage examples for org.springframework.web.context ContextLoaderListener ContextLoaderListener
public ContextLoaderListener(WebApplicationContext context)
From source file:ch.javaee.basicMvc.WebInitializer.java
@Override public void onStartup(ServletContext container) throws ServletException { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(AppConfiguration.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(DispatcherConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);// www.j a va 2s . com dispatcher.addMapping("/"); }
From source file:br.eti.danielcamargo.backend.common.config.WebAppInitializer.java
private WebApplicationContext createRootContext(ServletContext servletContext) { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CoreConfig.class, SecurityConfig.class); rootContext.refresh();/*ww w . j a va 2 s . c o m*/ servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.setInitParameter("defaultHtmlEscape", "true"); return rootContext; }
From source file:com.videohub.configuration.VideoHubInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { LOGGER.trace("Starting videohub app"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfiguration.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(DispatcherConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_NAME, new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);//from w ww.j ava 2 s .c om dispatcher.addMapping(DISPATCHER_MAPPING); }
From source file:org.avidj.zuul.rs.ZuulInitializer.java
@Override public void onStartup(ServletContext container) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootContextConfiguration.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(MvcContextConfiguration.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);//from w w w . j a v a 2 s . co m dispatcher.addMapping("/"); }
From source file:org.homiefund.init.WebAppBoostrapper.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfiguration.class, SecurityConfiguration.class); servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.addListener(new RequestContextListener()); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(MvcConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);/*from ww w .ja v a 2 s.c o m*/ dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); servletContext.addFilter("encodingFilter", new CharacterEncodingFilter("UTF-8", true)) .addMappingForUrlPatterns(null, false, "/*"); servletContext.addFilter("httpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); }
From source file:com.alliander.osgp.signing.server.application.config.SigningServerInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {//from w w w. jav a 2s .c om // Force the timezone of application to UTC (required for // Hibernate/JDBC) TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Context initialContext = new InitialContext(); final String logLocation = (String) initialContext.lookup("java:comp/env/osp/signingServer/log-config"); LogbackConfigurer.initLogging(logLocation); final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); servletContext.addListener(new ContextLoaderListener(rootContext)); } catch (final NamingException e) { throw new ServletException("Naming exception", e); } catch (final FileNotFoundException e) { throw new ServletException("Logging file not found", e); } catch (final JoranException e) { throw new ServletException("Logback exception", e); } }
From source file:com.sky.HibakeSeoBootApplication.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { log.info(" prerenderFilter "); //servletContext.addFilter("prerenderFilter", PrerenderFilter.class); servletContext.addFilter("seoFilter", CustomSEOFilter.class); WebApplicationContext rootAppContext = createRootApplicationContext(servletContext); if (rootAppContext != null) { servletContext.addListener(new ContextLoaderListener(rootAppContext) { @Override/*from w w w. ja va2s . co m*/ public void contextInitialized(ServletContextEvent event) { // no-op because the application context is already initialized } }); } else { this.logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not " + "return an application context"); } }
From source file:com.miserablemind.butter.bootstrap.AppInitializer.java
/** * Implements {@link WebApplicationInitializer} onStartup to initialize the system. * It registers and configures {@link RootContext}, {@link WebSecurityContext}, and app specific contexts. * It also initializes the {@link Log4jConfigListener}. * * @param container ServletContext// w w w .j a va 2s . co m */ @Override public void onStartup(ServletContext container) { //Make the logger read settings from main properties file container.setInitParameter("log4jConfigLocation", "classpath:system.properties"); container.addListener(new Log4jConfigListener()); //Root Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootContext.class); container.addListener(new ContextLoaderListener(rootContext)); //Spring Security context AnnotationConfigWebApplicationContext securityContext = new AnnotationConfigWebApplicationContext(); securityContext.register(WebSecurityContext.class); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("springSecurityFilterChain"); container.addFilter("springSecurityFilterChain", filterProxy).addMappingForUrlPatterns(null, false, "*"); //Dispatcher Servlet context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(ButterAppMVCContext.class); //Register and map the dispatcher servlet DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext); ServletRegistration.Dynamic dispatcher = container.addServlet("mvc-dispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
From source file:com.kajj.tools.logviewer.config.LogViewerWebApplicationInitializer.java
/** * Initialization method for the ServletContext. Creates the Spring context and * DispatcherServlet.//from w w w . ja v a 2s . c o m * * @param servletContext The ServletContext to initialize. * @throws ServletException If the ServletContext fails to initialize. */ @Override public void onStartup(final ServletContext servletContext) throws ServletException { final AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext(); springContext.setConfigLocation("com.kajj.tools.logviewer.config"); servletContext.addListener(new ContextLoaderListener(springContext)); final DispatcherServlet servlet = new DispatcherServlet(springContext); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, servlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(MAPPING_ANY); }
From source file:org.uoiu.platform.web.DefaultWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); // appContext.register(AppConfig.class); appContext.getEnvironment().setActiveProfiles("webapp"); servletContext.addListener(new ContextLoaderListener(appContext)); AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(MvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext)); dispatcher.setLoadOnStartup(1);//from w w w .j av a2s . co m dispatcher.addMapping("/"); FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", characterEncodingFilter()); encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); }