List of usage examples for org.springframework.context.support GenericApplicationContext refresh
@Override public void refresh() throws BeansException, IllegalStateException
From source file:org.joinfaces.annotations.JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java
@Test public void testViewScopedClass() { GenericApplicationContext acx = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(acx); acx.registerBeanDefinition("viewScopedClass", new AnnotatedGenericBeanDefinition(new StandardAnnotationMetadata(ViewScopedClass.class))); acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(ScopedBeansConfiguration.class)); acx.addBeanFactoryPostProcessor(new JsfCdiToSpringBeanFactoryPostProcessor()); acx.refresh(); assertThat(acx.getBeanDefinition("viewScopedClass").getScope()).isEqualTo(JsfCdiToSpring.VIEW); assertThat(acx.getBeanDefinition("viewScopedBean").getScope()).isEqualTo(JsfCdiToSpring.VIEW); }
From source file:org.joinfaces.annotations.JsfCdiToSpringApplicationBeanFactoryPostProcessorIT.java
@Test public void testSessionScopedClass() { GenericApplicationContext acx = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(acx); acx.registerBeanDefinition("sessionScopedClass", new AnnotatedGenericBeanDefinition(new StandardAnnotationMetadata(SessionScopedClass.class))); acx.registerBeanDefinition("scopedBeansConfiguration", new RootBeanDefinition(ScopedBeansConfiguration.class)); acx.addBeanFactoryPostProcessor(new JsfCdiToSpringBeanFactoryPostProcessor()); acx.refresh(); assertThat(acx.getBeanDefinition("sessionScopedClass").getScope()).isEqualTo(JsfCdiToSpring.SESSION); assertThat(acx.getBeanDefinition("sessionScopedBean").getScope()).isEqualTo(JsfCdiToSpring.SESSION); }
From source file:com.hybris.backoffice.cockpitng.search.DefaultAdvancedSearchOperatorServiceTest.java
@Override public void prepareApplicationContextAndSession() { final ApplicationContext parentApplicationContext = getApplicationContext(); final GenericApplicationContext applicationContext = new GenericApplicationContext( parentApplicationContext);//from w w w . j a v a 2 s . c o m final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); xmlReader.loadBeanDefinitions(new ByteArrayResource(BEANS_DEFINITION.getBytes())); applicationContext.refresh(); autowireProperties(applicationContext); }
From source file:org.wildfly.extension.camel.SpringCamelContextFactory.java
private static CamelContext createSpringCamelContext(Resource resource, ClassLoader classLoader) throws Exception { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(classLoader); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext) { @Override// w ww.j av a 2 s.co m protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver(); return new CamelNamespaceHandlerResolver(defaultResolver); } }; xmlReader.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputStream inputStream = null; if (CAMEL_SPRING_SYSTEM_ID.equals(systemId)) { inputStream = SpringCamelContext.class.getResourceAsStream("/camel-spring.xsd"); } else if (SPRING_BEANS_SYSTEM_ID.equals(systemId)) { inputStream = XmlBeanDefinitionReader.class.getResourceAsStream("spring-beans-3.1.xsd"); } InputSource result = null; if (inputStream != null) { result = new InputSource(); result.setSystemId(systemId); result.setByteStream(inputStream); } return result; } }); xmlReader.loadBeanDefinitions(resource); appContext.refresh(); return SpringCamelContext.springCamelContext(appContext); }
From source file:com.sitewhere.server.SiteWhereServer.java
/** * Load the springified server configuration. * //from w w w. j a v a2s .com * @return */ protected ApplicationContext loadServerApplicationContext(File configFile) throws SiteWhereException { GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new FileSystemResource(configFile)); context.refresh(); return context; }
From source file:org.finra.jtaf.core.AutomationEngine.java
private AutomationEngine() { try {/* ww w. j a v a2s . c o m*/ InputStream fi = getFrameworkFile(); GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); xmlReader.loadBeanDefinitions(new InputSource(fi)); ctx.refresh(); this.pluginManager = (PluginManager) ctx.getBean("PluginManager"); digraph = new TestDigraph(new ClassBasedEdgeFactory<DiNode, DiEdge>(DiEdge.class)); commandlibParser = new CommandLibraryParser(); scriptParser = new ScriptParser(); scriptParser.setDigraph(digraph); commandlibParser.setAutomationClassLoader(new DefaultAutomationClassLoader()); testStrategyParser = new TestStrategyParser(); testStrategyParser.setDigraph(digraph); initPostParseStrategyElementPlugins(); testRoot = null; this.interpreter = (Interpreter) ctx.getBean("Interpreter"); this.interpreter.setCommandRunnerPlugins(pluginManager.getCommandRunnerPlugins()); this.interpreter.setTestRunnerPlugins(pluginManager.getTestRunnerPlugins()); initPostParseAllPlugins(); initPostParseSuitePlugins(); initPostParseTestPlugins(); } catch (Exception e) { // If something goes wrong here, we have a serious issue logger.fatal(e); throw new RuntimeException(e); } }
From source file:edu.internet2.middleware.shibboleth.common.config.BaseService.java
/** * Loads the service context./*w ww. j ava 2 s.c o m*/ * * @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:com.retroduction.carma.application.CarmaDriverSetup.java
public void init() { GenericApplicationContext newAppContext = new GenericApplicationContext(this.parentContext); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(newAppContext); for (String res : this.beanDefinitionResources) { xmlReader.loadBeanDefinitions(res); }/* ww w .j a va 2 s .c om*/ PropertyPlaceholderConfigurer customerPropsProcessor = new PropertyPlaceholderConfigurer(); customerPropsProcessor.setProperties(this.configurationParameters); newAppContext.addBeanFactoryPostProcessor(customerPropsProcessor); newAppContext.refresh(); newAppContext.registerShutdownHook(); this.appContext = newAppContext; }
From source file:org.mybatis.spring.config.NamespaceTest.java
private GenericApplicationContext setupSqlSessionFactory() { GenericApplicationContext genericApplicationContext = new GenericApplicationContext(); GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(SqlSessionFactoryBean.class); definition.getPropertyValues().add("dataSource", new MockDataSource()); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("sqlSessionFactory", definition); genericApplicationContext.registerBeanDefinition("sqlSessionFactory", definition); genericApplicationContext.refresh(); return genericApplicationContext; }
From source file:com.graphaware.server.foundation.context.FoundationRootContextCreator.java
@Override public AbstractApplicationContext createContext(NeoServer neoServer, StatsCollector statsCollector) { GenericApplicationContext parent = new GenericApplicationContext(); parent.registerShutdownHook();/*from w w w. j a v a 2s . c o m*/ parent.getBeanFactory().registerSingleton("database", neoServer.getDatabase().getGraph()); parent.getBeanFactory().registerSingleton("procedures", neoServer.getDatabase().getGraph().getDependencyResolver().resolveDependency(Procedures.class)); parent.getBeanFactory().registerSingleton("getStatsCollector", statsCollector); GraphAwareRuntime runtime = RuntimeRegistry.getRuntime(neoServer.getDatabase().getGraph()); if (runtime != null) { runtime.waitUntilStarted(); parent.getBeanFactory().registerSingleton("databaseWriter", runtime.getDatabaseWriter()); } parent.refresh(); return parent; }