List of usage examples for org.springframework.web.context ContextLoaderListener ContextLoaderListener
public ContextLoaderListener(WebApplicationContext context)
From source file:com.rockagen.gnext.main.BootStrap.java
protected void addListeners(final ServletContext ctx) { ctx.addListener(new ContextLoaderListener(rootContext)); Log4jConfigListener lcl = new Log4jConfigListener(); ctx.addListener(lcl);//from w w w.j a va2 s.c om }
From source file:io.springagora.store.AppInitializer.java
/** * Creates the Spring Root Context, which is the context providing core features * to the application, like the database layer configuration, aspect configuration * ando so on. This is loaded by the Spring's context listener. * //from w ww . j ava 2 s. c o m * @param container * Container where all web objects are going to be registered. */ private void initializeSpringContext(ServletContext container) { // // The root context is created upon all definition contained in the Java class, // (SpringAppConfig) containing the Spring initialization directives. // AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfig.class); container.addListener(new ContextLoaderListener(rootContext)); }
From source file:com.techtrip.dynbl.context.config.WebAppinitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Setup Context to Accept Annotated Classes on Input (including plain Spring {@code @Component} // Stereotypes in addition to JSR-330 Compliant Classes using {@code javax.inject} AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); //context.setConfigLocation(APP_CONFIG_LOCATION); context.setConfigLocation(APP_CONFIG_LOCATION); /* /*from w w w . ja v a 2s . c o m*/ * Add a Spring Security Filter using the JEE6 Filter Registration Filter Method from {@code FilterRegistration) that allows filters to be registered * and configured with the specified context */ /* FilterRegistration.Dynamic securityFilter = servletContext.addFilter(ProjectKeyValConsts.SECURITY_FILTER.getKey(), new DelegatingFilterProxy(ProjectKeyValConsts.SECURITY_FILTER.getValue())); securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ProjectConsts.BASE_URL_MAPPING_PATTERN.getValue()); // where the filter will be applied */ // Add a Character Encoding Filter that specifies an encoding for mapped requests FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ROOT_CONTEXT); // where the filter will be applied characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", Boolean.TRUE.toString()); characterEncodingFilter.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(context)); servletContext.setInitParameter("defaultHtmlEscape", Boolean.TRUE.toString()); DispatcherServlet servlet = new DispatcherServlet(); // no explicit configuration reference here: everything is configured in the root container for simplicity servlet.setContextConfigLocation(""); /* TMT From JEE 6 API Docs: * Registers the given servlet instance with this ServletContext under the given servletName. * The registered servlet may be further configured via the returned ServletRegistration object. */ ServletRegistration.Dynamic appServlet = servletContext.addServlet(APP_SERVLET, servlet); appServlet.setLoadOnStartup(1); appServlet.setAsyncSupported(true); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException(String.format( "The servlet named '%s' cannot be mapped to '/' under Tomcat versions <= 7.0.14", APP_SERVLET)); } // TMT servletContext.addListener(new Log4jConfigListener()); System.out.println("Application inplemented on Spring Version: " + SpringVersion.getVersion()); }
From source file:com.gosmarter.it.eis.config.ExcelERPWebApplicationInitializer.java
private void registerListener(ServletContext servletContext) { AnnotationConfigWebApplicationContext rootContext = createContext(configurationClasses); servletContext.addListener(new RequestContextListener()); servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.addListener(new HttpSessionListener()); servletContext.addListener(new WebDbInitializer()); }
From source file:fr.treeptik.cloudunit.initializer.ApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CloudUnitApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/*from w w w. j av a 2s . com*/ dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); dispatcher.setAsyncSupported(true); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/nopublic/*"); security.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:cz.muni.fi.editor.webapp.config.init.EditorApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { String bootLogo = " __ __ _ _ _ _ _ _ \n" + " | \\/ | | | | | | | | (_) | \n" + " | \\ / | ___| |_ __ _ __| | __ _| |_ __ _ ___ __| |_| |_ ___ _ __ \n" + " | |\\/| |/ _ \\ __/ _` |/ _` |/ _` | __/ _` | / _ \\/ _` | | __/ _ \\| '__|\n" + " | | | | __/ || (_| | (_| | (_| | || (_| | | __/ (_| | | || (_) | | \n" + " |_| |_|\\___|\\__\\__,_|\\__,_|\\__,_|\\__\\__,_| \\___|\\__,_|_|\\__\\___/|_| \n" + " \n" + " "; System.out.println(ANSI_YELLOW + bootLogo + ANSI_RESET); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().setActiveProfiles("production"); rootContext.register(WebAppConfiguration.class, SecurityConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(MvcConfiguration.class, WebSocketSecurityConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);/* w ww . ja va2 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:io.gravitee.management.standalone.jetty.JettyEmbeddedContainer.java
@Override protected void doStart() throws Exception { AbstractHandler noContentHandler = new NoContentOutputErrorHandler(); // This part is needed to avoid WARN while starting container. noContentHandler.setServer(server);//ww w . j a v a 2 s. com server.addBean(noContentHandler); // Create the servlet context final ServletContextHandler context = new ServletContextHandler(server, "/management/*", ServletContextHandler.SESSIONS); // REST configuration final ServletHolder servletHolder = new ServletHolder(ServletContainer.class); servletHolder.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName()); servletHolder.setInitOrder(0); context.addServlet(servletHolder, "/*"); // Spring configuration System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, securityImplementation); AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); webApplicationContext.register(SecurityConfiguration.class); webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment()); webApplicationContext.setParent(applicationContext); context.addEventListener(new ContextLoaderListener(webApplicationContext)); // Spring Security filter context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class)); // start the server server.start(); }
From source file:cn.org.once.cstack.initializer.ApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CloudUnitApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);// w w w . j av a2 s. co m dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); dispatcher.setAsyncSupported(true); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/scripting/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/gitlab/*"); security.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:org.bonitasoft.web.designer.SpringWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { for (String line : BANNER) { logger.info(line);//from w w w .ja v a 2s . com } logger.info(Strings.repeat("=", 100)); logger.info(String.format("UI-DESIGNER : %s edition v.%s", prop.getProperty("designer.edition"), prop.getProperty("designer.version"))); logger.info(Strings.repeat("=", 100)); // Create the root context Spring AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(new Class<?>[] { ApplicationConfig.class }); // Manage the lifecycle of the root application context servletContext.addListener(new ContextLoaderListener(rootContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir"))); dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); }
From source file:com.dominion.salud.pedicom.configuration.PEDICOMInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.scan("com.dominion.salud.pedicom.configuration"); ctx.setServletContext(servletContext); PEDICOMConstantes._NOMBRE_CONFIG = servletContext.getInitParameter("NOMBRE_CONFIG"); System.setProperty("pedicom.conf.home", findConfigurationAndLogger(ctx)); ctx.refresh();//from w ww . j a v a2 s.c o m // Spring Dispatcher ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); dispatcher.setInitParameter("contextClass", ctx.getClass().getName()); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); dispatcher.addMapping("/controller/*"); servletContext.addListener(new ContextLoaderListener(ctx)); // Configuracion general PEDICOMConstantes._HOME = StringUtils.endsWith(servletContext.getRealPath("/"), File.separator) ? servletContext.getRealPath("/") : servletContext.getRealPath("/") + File.separator; PEDICOMConstantes._CONF_HOME = ctx.getEnvironment().getProperty("pedicom.conf.home"); PEDICOMConstantes._TEMP = PEDICOMConstantes._HOME + "WEB-INF" + File.separator + "temp" + File.separator; PEDICOMConstantes._VERSION = ResourceBundle.getBundle("version").getString("version"); PEDICOMConstantes._LOGS = PEDICOMConstantes._HOME + "WEB-INF" + File.separator + "classes" + File.separator + "logs"; PEDICOMConstantes._CONTEXT_NAME = servletContext.getServletContextName(); PEDICOMConstantes._CONTEXT_PATH = servletContext.getContextPath(); PEDICOMConstantes._CONTEXT_SERVER = servletContext.getServerInfo(); PEDICOMConstantes._ENABLE_TECHNICAL_INFORMATION = StringUtils.isNotBlank( ResourceBundle.getBundle("application").getString("pedicom.enable.technical.information")) ? Boolean.parseBoolean(ResourceBundle.getBundle("application") .getString("pedicom.enable.technical.information")) : false; PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON = StringUtils .isNotBlank(ResourceBundle.getBundle("application").getString("pedicom_scheduler_send_mail_cron")) ? PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON = ResourceBundle.getBundle("application") .getString("pedicom_scheduler_send_mail_cron") : PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON; PEDICOMConstantes._SCHEDULER_UPDATE_EXISTENCIAS_CRON = StringUtils.isNotBlank( ResourceBundle.getBundle("application").getString("pedicom_scheduler_update_existencias_cron")) ? PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON = ResourceBundle.getBundle("application") .getString("pedicom_scheduler_update_existencias_cron") : PEDICOMConstantes._SCHEDULER_UPDATE_EXISTENCIAS_CRON; // Configuracion de LOGS DEL MODULO if (StringUtils.isBlank( ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile())) { ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")) .setFile(PEDICOMConstantes._HOME + "WEB-INF" + File.separator + "classes" + File.separator + "logs" + File.separator + "mpr-desktop.log"); } PEDICOMConstantes._LOGS = new File( ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile()) .getParent(); Environment env = ctx.getEnvironment(); XmlUnmarshaler xml = new XmlUnmarshaler(); Datos datos = (Datos) xml.unmarshal(); logger.info(" Datasources"); for (Datasources dat : datos.getDatasources()) { if (dat.getNombreDatasource().equals("Central")) { PEDICOMConstantes.EXISTENCIAS_EXISTE = true; } logger.info(" codCentro: " + dat.getCodCentro()); logger.info(" nombreDatasource: " + dat.getNombreDatasource()); logger.info(" driverClassName: " + dat.getDriverClassName()); logger.info(" jndi: " + dat.getJndi()); logger.info(" url: " + dat.getUrl()); logger.info(" username: " + dat.getUsername()); logger.info(" usernameEmail: " + dat.getUsernameEmail()); logger.info(" passwordEmail: " + dat.getPasswordEmail()); logger.info(" from: " + dat.getFrom()); logger.info(" host: " + dat.getHost()); logger.info(" port: " + dat.getPort()); logger.info(" TLS: " + dat.getTLS()); logger.info(" SSL: " + dat.getSSL()); } // ctx.refresh(); // PropertyConfigurator.configureAndWatch("log4j"); logger.info(" Configuracion general del sistema"); logger.info(" pedicom.home: " + PEDICOMConstantes._HOME); logger.info(" pedicom.conf.home: " + PEDICOMConstantes._CONF_HOME); logger.info(" pedicom.temp: " + PEDICOMConstantes._TEMP); logger.info(" pedicom.version: " + PEDICOMConstantes._VERSION); logger.info(" pedicom.logs: " + PEDICOMConstantes._LOGS); logger.info(" pedicom.context.name: " + PEDICOMConstantes._CONTEXT_NAME); logger.info(" pedicom.context.path: " + PEDICOMConstantes._CONTEXT_PATH); logger.info(" pedicom.context.server: " + PEDICOMConstantes._CONTEXT_SERVER); logger.info(" Parametrizacion del sistema"); logger.info(" pedicom.enable.technical.information: " + PEDICOMConstantes._ENABLE_TECHNICAL_INFORMATION); logger.info( " pedicom_scheduler_send_mail_cron: " + PEDICOMConstantes._SCHEDULER_SEND_MAIL_CRON); logger.info(" pedicom_scheduler_update_existencias_cron: " + PEDICOMConstantes._SCHEDULER_UPDATE_EXISTENCIAS_CRON); logger.info(" Modulo configurado correctamente"); logger.info("MODULO INICIADO CORRECTAMENTE"); }