List of usage examples for javax.servlet ServletContext addListener
public void addListener(Class<? extends EventListener> listenerClass);
From source file:net.orpiske.tcs.service.config.WebAppInitializer.java
private WebApplicationContext createRootContext(ServletContext servletContext) { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CoreConfig.class, SecurityConfig.class); rootContext.refresh();/* w w w.j a v a 2s .c om*/ servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.setInitParameter("defaultHtmlEscape", "true"); return rootContext; }
From source file:com.googlecode.jeeunit.example.spring.web.LibraryWebApplicationInitializer.java
@Override public void onStartup(ServletContext sc) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().addActiveProfile("web"); rootContext.register(WebSpringConfig.class); sc.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.setParent(rootContext); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(2);//w w w .j a v a 2 s . c o m dispatcher.addMapping("*.html"); dispatcher.addMapping("*.form"); dispatcher.addMapping("*.ajax"); }
From source file:olsps.com.healthsoftproject.config.SpringWebAppInitializer.java
@Override public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfigClass.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/*from w w w . ja v a 2s . c o 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 w w w . j av 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:wqm.radio.StationManager.java
@Autowired public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; servletContext.addListener(this); }
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);/*w w w .j av a2 s .co m*/ dispatcher.addMapping(DISPATCHER_MAPPING); }
From source file:com.test.config.BackendConsoleWebConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); webCtx.register(BackendConsoleMVCConfig.class); webCtx.register(BackendConsoleConfig.class); servletContext.addListener(new ContextLoaderListener(webCtx)); /* Spring Delegating Dispatcher Servlet */ Servlet dispatcherServlet = new DispatcherServlet(webCtx); ServletRegistration.Dynamic dispatcherServletReg = servletContext.addServlet("dispatcherServlet", dispatcherServlet);/* w ww. j ava2 s . c om*/ dispatcherServletReg.setLoadOnStartup(1); dispatcherServletReg.setInitParameter("contextConfigLocation", ""); dispatcherServletReg.addMapping("/"); /* Spring Security Delegating Filter */ FilterRegistration springSecurityFilterChainReg = servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class); springSecurityFilterChainReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.ASYNC), false, dispatcherServletReg.getName()); }
From source file:sg.edu.ntu.hrms.web.action.WebInit.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(AppConfig.class); ContextLoaderListener contextLoaderListener = new ContextLoaderListener(appContext); servletContext.addListener(contextLoaderListener); /*//from ww w .j a va 2s . co m FilterRegistration.Dynamic filter = servletContext.addFilter( "StrutsDispatcher", new StrutsPrepareAndExecuteFilter()); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); */ }
From source file:com.pojur.config.AppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // WebApplicationContext context = getContext(); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ServiceConfig.class, JPAConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(WebMvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1);/* w w w. ja v a 2s . c om*/ dispatcher.addMapping("/"); }
From source file:com.mycompany.spring2explore.config.WebAppInitializer.java
@Override public void onStartup(ServletContext cs) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringRootConfig.class); // Manage the lifecycle of the root application context cs.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(MvcConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = cs.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1);/*from w w w. java2 s . c om*/ dispatcher.addMapping("/"); }