List of usage examples for org.springframework.context.support GenericApplicationContext setDisplayName
public void setDisplayName(String displayName)
From source file:fi.okm.mpass.shibboleth.profile.metadata.DataSourceMetadataResolverTest.java
@SuppressWarnings("unchecked") protected <Type> Type getBean(String fileName, Class<Type> claz, GenericApplicationContext context, boolean supressValid) { context.setDisplayName("ApplicationContext: " + claz); loadFile(fileName, context, supressValid); context.refresh();// w w w .j a v a2 s . com return (Type) ((RelyingPartyMetadataProvider) context.getBean("dataSourceEntity")).getEmbeddedResolver(); }
From source file:edu.internet2.middleware.shibboleth.common.config.BaseService.java
/** * Loads the service context.//from w w w . j av a 2 s .com * * @throws ServiceException thrown if the configuration for this service could not be loaded */ protected void loadContext() throws ServiceException { log.info("Loading new configuration for service {}", getId()); if (serviceConfigurations == null || serviceConfigurations.isEmpty()) { setInitialized(true); return; } GenericApplicationContext newServiceContext = new GenericApplicationContext(getApplicationContext()); newServiceContext.setDisplayName("ApplicationContext:" + getId()); Lock writeLock = getReadWriteLock().writeLock(); writeLock.lock(); try { SpringConfigurationUtils.populateRegistry(newServiceContext, getServiceConfigurations()); newServiceContext.refresh(); GenericApplicationContext replacedServiceContext = serviceContext; onNewContextCreated(newServiceContext); setServiceContext(newServiceContext); setInitialized(true); if (replacedServiceContext != null) { replacedServiceContext.close(); } log.info("{} service loaded new configuration", getId()); } catch (Throwable e) { // Here we catch all the other exceptions thrown by Spring when it starts up the context setInitialized(false); Throwable rootCause = e; while (rootCause.getCause() != null) { rootCause = rootCause.getCause(); } log.error("Configuration was not loaded for " + getId() + " service, error creating components. The root cause of this error was: " + rootCause.getClass().getCanonicalName() + ": " + rootCause.getMessage()); log.trace("Full stacktrace is: ", e); throw new ServiceException( "Configuration was not loaded for " + getId() + " service, error creating components.", rootCause); } finally { writeLock.unlock(); } }
From source file:org.lilyproject.runtime.module.build.ModuleBuilder.java
private Module buildInt(ModuleConfig cfg, ClassLoader classLoader, LilyRuntime runtime) throws ArtifactNotFoundException, MalformedURLException { infolog.info("Starting module " + cfg.getId() + " - " + cfg.getLocation()); ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader(); try {//from ww w . j a v a 2 s .c o m Thread.currentThread().setContextClassLoader(classLoader); GenericApplicationContext applicationContext = new GenericApplicationContext(); applicationContext.setDisplayName(cfg.getId()); applicationContext.setClassLoader(classLoader); // Note: before loading any beans in the spring container: // * the spring build context needs access to the module, for possible injection & module-protocol resolving during bean initialization // * the module also needs to have the reference to the applicationcontext, as there might be beans trying to get while initializing ModuleImpl module = new ModuleImpl(classLoader, applicationContext, cfg.getDefinition(), cfg.getModuleSource()); SpringBuildContext springBuildContext = new SpringBuildContext(runtime, module, classLoader); SPRING_BUILD_CONTEXT.set(springBuildContext); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); xmlReader.setBeanClassLoader(classLoader); for (ModuleSource.SpringConfigEntry entry : cfg.getModuleSource().getSpringConfigs(runtime.getMode())) { InputStream is = entry.getStream(); try { xmlReader.loadBeanDefinitions(new InputStreamResource(is, entry.getLocation() + " in " + cfg.getDefinition().getFile().getAbsolutePath())); } finally { IOUtils.closeQuietly(is, entry.getLocation()); } } applicationContext.refresh(); // Handle the service exports for (SpringBuildContext.JavaServiceExport entry : springBuildContext.getExportedJavaServices()) { Class serviceType = entry.serviceType; if (!serviceType.isInterface()) { throw new LilyRTException("Exported service is not an interface: " + serviceType.getName()); } String beanName = entry.beanName; Object component; try { component = applicationContext.getBean(beanName); } catch (NoSuchBeanDefinitionException e) { throw new LilyRTException("Bean not found for service to export, service type " + serviceType.getName() + ", bean name " + beanName, e); } if (!serviceType.isAssignableFrom(component.getClass())) { throw new LilyRTException( "Exported service does not implemented specified type interface. Bean = " + beanName + ", interface = " + serviceType.getName()); } infolog.debug(" exporting bean " + beanName + " for service " + serviceType.getName()); Object service = shieldJavaService(serviceType, component, module, classLoader); runtime.getJavaServiceManager().addService(serviceType, cfg.getId(), entry.name, service); } module.start(); return module; } catch (Throwable e) { // TODO module source and classloader handle might need disposing! // especially important if the lily runtime is launched as part of a longer-living VM throw new LilyRTException( "Error constructing module defined at " + cfg.getDefinition().getFile().getAbsolutePath(), e); } finally { Thread.currentThread().setContextClassLoader(previousContextClassLoader); SPRING_BUILD_CONTEXT.set(null); } }