List of usage examples for org.springframework.context ConfigurableApplicationContext getClassLoader
@Nullable ClassLoader getClassLoader();
From source file:net.opentsdb.contrib.tsquare.support.TsWebApplicationContextInitializer.java
@Override public void initialize(final ConfigurableApplicationContext applicationContext) { final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( applicationContext.getClassLoader()); try {// ww w.ja v a2s .c o m final TsdbConfigPropertySource config = loadTsdbConfig(resolver); log.info("Application config is using {}", config.getName()); applicationContext.getEnvironment().getPropertySources().addFirst(config); } catch (IOException e) { throw new BeanInitializationException("Unable to load a TSDB config file!", e); } }
From source file:org.ojb.web.portal.WebPortalApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); Properties props = new Properties(); String activeProfiles = ""; try {/*w w w.j av a 2 s . c o m*/ props.load(applicationContext.getClassLoader() .getResourceAsStream("config/ojb_web_external_resource.cfg")); activeProfiles = props.getProperty("spring.activeProfiles"); } catch (IOException e) { LOG.info( "Unable to load spring profiles from external resource, will load default from ojb_web_portal.cfg"); } if (StringUtils.isBlank(activeProfiles)) { try { props.clear(); props.load(applicationContext.getClassLoader().getResourceAsStream("config/ojb-web-portal.cfg")); activeProfiles = props.getProperty("spring.activeProfiles"); } catch (IOException e) { LOG.info("Unable to load spring profiles from ojb_web_portal.cfg"); } } if (StringUtils.isBlank(activeProfiles)) { LOG.info("No spring profiles set, will run in 'standalone' mode"); environment.setDefaultProfiles("standalone"); } else { LOG.info("Setting default profiles to:" + activeProfiles); environment.setDefaultProfiles(activeProfiles.split(",")); } }
From source file:org.springframework.boot.context.initializer.LoggingApplicationContextInitializer.java
/** * Initialize the logging system according to preferences expressed through the * {@link Environment} and the classpath. */// w w w. j a va 2s . com @Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (this.parseArgs && this.springBootLogging == null) { if (environment.containsProperty("debug")) { this.springBootLogging = LogLevel.DEBUG; } if (environment.containsProperty("trace")) { this.springBootLogging = LogLevel.TRACE; } } for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING.entrySet()) { if (environment.containsProperty(mapping.getKey())) { System.setProperty(mapping.getValue(), environment.getProperty(mapping.getKey())); } } LoggingSystem system = LoggingSystem.get(applicationContext.getClassLoader()); // User specified configuration if (environment.containsProperty("logging.config")) { String value = environment.getProperty("logging.config"); try { ResourceUtils.getURL(value).openStream().close(); system.initialize(value); return; } catch (Exception ex) { // Swallow exception and continue } this.logger.warn("Logging environment value '" + value + "' cannot be opened and will be ignored"); } system.initialize(); if (this.springBootLogging != null) { initializeLogLevel(system, this.springBootLogging); } }
From source file:org.springframework.boot.diagnostics.FailureAnalyzers.java
FailureAnalyzers(ConfigurableApplicationContext context, ClassLoader classLoader) { Assert.notNull(context, "Context must not be null"); this.classLoader = (classLoader == null ? context.getClassLoader() : classLoader); this.analyzers = loadFailureAnalyzers(this.classLoader); prepareFailureAnalyzers(this.analyzers, context); }
From source file:org.springframework.cloud.stream.config.BinderFactoryConfiguration.java
@Bean public BinderTypeRegistry binderTypeRegistry(ConfigurableApplicationContext configurableApplicationContext) { Map<String, BinderType> binderTypes = new HashMap<>(); ClassLoader classLoader = configurableApplicationContext.getClassLoader(); // the above can never be null since it will default to ClassUtils.getDefaultClassLoader(..) try {/*from w w w .j a v a2s . com*/ Enumeration<URL> resources = classLoader.getResources("META-INF/spring.binders"); if (!Boolean.valueOf(this.selfContained) && (resources == null || !resources.hasMoreElements())) { this.logger.debug("Failed to locate 'META-INF/spring.binders' resources on the classpath." + " Assuming standard boot 'META-INF/spring.factories' configuration is used"); } else { while (resources.hasMoreElements()) { URL url = resources.nextElement(); UrlResource resource = new UrlResource(url); for (BinderType binderType : parseBinderConfigurations(classLoader, resource)) { binderTypes.put(binderType.getDefaultName(), binderType); } } } } catch (IOException | ClassNotFoundException e) { throw new BeanCreationException("Cannot create binder factory:", e); } return new DefaultBinderTypeRegistry(binderTypes); }