List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext refresh
@Override public void refresh() throws BeansException, IllegalStateException
From source file:com.setronica.ucs.server.MessageServer.java
private static ClassPathXmlApplicationContext initApplication(String profile, DefaultListableBeanFactory parentBeanFactory) { ClassPathXmlApplicationContext applicationContext; if (parentBeanFactory != null) { //wrap BeanFactory inside ApplicationContext GenericApplicationContext parentContext = new GenericApplicationContext(parentBeanFactory); parentContext.refresh();//from w w w .j ava 2 s . c o m applicationContext = new ClassPathXmlApplicationContext(parentContext); } else { applicationContext = new ClassPathXmlApplicationContext(); } ConfigurableEnvironment environment = applicationContext.getEnvironment(); environment.setDefaultProfiles(profile); applicationContext.setConfigLocation("spring-application.xml"); // log active profile String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); } for (String activeProfile : profiles) { if (environment.acceptsProfiles(activeProfile)) { logger.info("Profile " + activeProfile + " is active"); } } applicationContext.refresh(); return applicationContext; }
From source file:com.vmware.o11n.plugin.PowerShellPluginAdaptor.java
@Override protected ApplicationContext createApplicationContext(ApplicationContext defaultParent) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { DEFAULT_CONFIG }, false, defaultParent); pluginClassLoader = getClass().getClassLoader();//we expect spring applicationContext.setClassLoader(pluginClassLoader); applicationContext.refresh(); return applicationContext; }
From source file:org.atomserver.core.dbstore.utils.SeederDBSTest.java
public void testSeedDB() throws Exception { if (hasRun) { return;/*from w w w .j a v a 2s . co m*/ } String[] configs = { "/org/atomserver/spring/propertyConfigurerBeans.xml", "/org/atomserver/spring/logBeans.xml", "/org/atomserver/spring/storageBeans.xml", "/org/atomserver/spring/databaseBeans.xml" }; ClassPathXmlApplicationContext springFactory = new ClassPathXmlApplicationContext(configs, false); springFactory.setClassLoader(new ConfigurationAwareClassLoader(springFactory.getClassLoader())); springFactory.refresh(); try { DBSeeder.getInstance(springFactory).seedEntriesClearingFirst(); } catch (Exception ee) { ee.printStackTrace(); } hasRun = true; // We should now get an ordered List back // SORTED -- From the beginning of time EntriesDAO widgetsDAOiBatis = (EntriesDAO) springFactory.getBean("org.atomserver-entriesDAO"); List sortedList = widgetsDAOiBatis .selectEntriesByLastModifiedSeqNum(new BaseFeedDescriptor("widgets", null), ZERO_DATE); log.debug("List= " + sortedList); Date lastVal = ZERO_DATE; long seqNum = 0; for (Object obj : sortedList) { EntryMetaData widget = (EntryMetaData) obj; assertTrue(lastVal.compareTo(widget.getUpdatedDate()) <= 0); lastVal = widget.getUpdatedDate(); assertTrue("expected " + seqNum + " < " + widget.getUpdateTimestamp() + " for " + widget, seqNum < widget.getUpdateTimestamp()); seqNum = widget.getUpdateTimestamp(); } }
From source file:com.verigreen.common.spring.SpringContextLoader.java
@Override public ApplicationContext loadContext(String... locations) { String[] allLocations = generateConfigLocations(Arrays.asList(locations)); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(allLocations, false); /*/*from w w w .j a v a 2s . c o m*/ * Set validating=false to avoid validation of XML configuration files. * This decreases startup time significantly. */ context.setValidating(false); context.refresh(); // Load the context. SpringContextHolder.getInstance().setApplicationContext(context); return context; }
From source file:guru.qas.martini.jmeter.config.DefaultApplicationContextBuilder.java
protected ConfigurableApplicationContext build(String[] locations) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(locations, false); setProfiles(context);/* ww w.j a v a2 s. c o m*/ setEnvironment(context); String id = new AlternativeJdkIdGenerator().generateId().toString(); context.setId(id); context.refresh(); return context; }
From source file:org.atomserver.core.EntryURIHelperTest.java
protected void setUp() throws Exception { String[] configs = { "/org/atomserver/spring/propertyConfigurerBeans.xml", "/org/atomserver/spring/databaseBeans.xml", "/org/atomserver/spring/storageBeans.xml", "/org/atomserver/spring/logBeans.xml", "/org/atomserver/spring/abderaBeans.xml" }; ClassPathXmlApplicationContext springFactory = new ClassPathXmlApplicationContext(configs, false); springFactory.setClassLoader(new ConfigurationAwareClassLoader(springFactory.getClassLoader())); springFactory.refresh(); handler = ((AbstractAtomService) springFactory.getBean("org.atomserver-atomService")).getURIHandler(); serviceContext = (ServiceContext) springFactory.getBean(CONTEXT_NAME); if (serviceContext.getAbdera() == null) { serviceContext.init(new Abdera(), null); }/* w w w. j a v a2 s.co m*/ baseURI = handler.getServiceBaseUri(); }
From source file:org.pentaho.pat.plugin.PatLifeCycleListener.java
public void loaded() throws PluginLifecycleException { ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader(); IServiceManager serviceManager = (IServiceManager) PentahoSystem.get(IServiceManager.class, PentahoSessionHolder.getSession()); try {/*from w ww. j av a2 s . c om*/ sessionBean = (SessionServlet) serviceManager.getServiceBean("gwt", "session.rpc"); //$NON-NLS-1$ queryBean = (QueryServlet) serviceManager.getServiceBean("gwt", "query.rpc"); //$NON-NLS-1$ discoveryBean = (DiscoveryServlet) serviceManager.getServiceBean("gwt", "discovery.rpc"); //$NON-NLS-1$ platformBean = (PlatformServlet) serviceManager.getServiceBean("gwt", "platform.rpc"); //$NON-NLS-1$ final IPluginManager pluginManager = (IPluginManager) PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession()); final PluginClassLoader pluginClassloader = (PluginClassLoader) pluginManager .getClassLoader(PAT_PLUGIN_NAME); final String hibernateConfigurationFile = PentahoSystem .getSystemSetting("hibernate/hibernate-settings.xml", "settings/config-file", null); //$NON-NLS-1$ final String pentahoHibConfigPath = PentahoSystem.getApplicationContext() .getSolutionPath(hibernateConfigurationFile); if (pluginClassloader == null) throw new ServiceException(Messages.getString("LifeCycleListener.NoPluginClassloader")); //$NON-NLS-1$ Thread.currentThread().setContextClassLoader(pluginClassloader); final URL contextUrl = pluginClassloader.getResource(PAT_APP_CONTEXT); final URL patHibConfigUrl = pluginClassloader.getResource(PAT_HIBERNATE_CONFIG); final URL patPluginPropertiesUrl = pluginClassloader.getResource(PAT_PLUGIN_PROPERTIES); if (patHibConfigUrl == null) throw new ServiceException("File not found: PAT Hibernate Config : " + PAT_HIBERNATE_CONFIG); else LOG.debug(PAT_PLUGIN_NAME + ": PAT Hibernate Config:" + patHibConfigUrl.toString()); if (patPluginPropertiesUrl == null) throw new ServiceException("File not found: PAT Plugin properties : " + PAT_PLUGIN_PROPERTIES); else LOG.debug(PAT_PLUGIN_NAME + ": PAT Plugin Properties:" + patPluginPropertiesUrl.toString()); if (contextUrl != null) { String appContextUrl = contextUrl.toString(); final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { appContextUrl }, false); applicationContext.setClassLoader(pluginClassloader); applicationContext.setConfigLocation(appContextUrl); applicationContext.setAllowBeanDefinitionOverriding(true); final Configuration pentahoHibConfig = new Configuration(); pentahoHibConfig.configure(new File(pentahoHibConfigPath)); final AnnotationConfiguration patHibConfig = new AnnotationConfiguration(); patHibConfig.configure(patHibConfigUrl); Properties properties = new Properties(); properties.load(pluginClassloader.getResourceAsStream(PAT_PLUGIN_PROPERTIES)); String hibernateDialectCfg = (String) properties.get("pat.plugin.datasource.hibernate.dialect"); String hibernateDialect = null; if (StringUtils.isNotBlank(hibernateDialectCfg)) { if (hibernateDialectCfg.equals("auto")) { hibernateDialect = pentahoHibConfig.getProperty("dialect"); } else { hibernateDialect = hibernateDialectCfg; } } if (StringUtils.isNotBlank(hibernateDialect)) { patHibConfig.setProperty("hibernate.dialect", hibernateDialect); LOG.info(PAT_PLUGIN_NAME + " : using hibernate dialect: " + hibernateDialect); } String dataSourceType = (String) properties.get("pat.plugin.datasource.type"); String datasourceResource = null; if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jdbc")) { datasourceResource = PAT_DATASOURCE_JDBC; LOG.info(PAT_PLUGIN_NAME + " : using JDBC connection"); } if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jndi")) { datasourceResource = PAT_DATASOURCE_JNDI; LOG.info(PAT_PLUGIN_NAME + " : using JNDI : " + (String) properties.get("jndi.name")); } XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(datasourceResource)); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(new ClassPathResource(PAT_PLUGIN_PROPERTIES)); cfg.postProcessBeanFactory(factory); XmlBeanFactory bfSession = new XmlBeanFactory(new ClassPathResource(PAT_SESSIONFACTORY), factory); PropertyPlaceholderConfigurer cfgSession = new PropertyPlaceholderConfigurer(); cfgSession.setProperties(patHibConfig.getProperties()); cfgSession.postProcessBeanFactory(bfSession); ClassPathXmlApplicationContext tmpCtxt = new ClassPathXmlApplicationContext(); tmpCtxt.refresh(); DefaultListableBeanFactory tmpBf = (DefaultListableBeanFactory) tmpCtxt.getBeanFactory(); tmpBf.setParentBeanFactory(bfSession); applicationContext.setClassLoader(pluginClassloader); applicationContext.setParent(tmpCtxt); applicationContext.refresh(); sessionBean.setStandalone(true); SessionServlet.setApplicationContext(applicationContext); sessionBean.init(); queryBean.setStandalone(true); QueryServlet.setApplicationContext(applicationContext); queryBean.init(); discoveryBean.setStandalone(true); DiscoveryServlet.setApplicationContext(applicationContext); discoveryBean.init(); platformBean.setStandalone(true); PlatformServlet.setApplicationContext(applicationContext); platformBean.init(); injectPentahoXmlaUrl(); } else { throw new Exception(Messages.getString("LifeCycleListener.AppContextNotFound")); } } catch (ServiceException e1) { LOG.error(e1.getMessage(), e1); } catch (ServletException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { // reset the classloader of the current thread if (origContextClassloader != null) { Thread.currentThread().setContextClassLoader(origContextClassloader); } } }
From source file:org.cleverbus.core.common.extension.AbstractExtensionConfigurationLoader.java
private void loadExtension(String extConfigLocation, int extNumber) throws Exception { Log.debug("new extension context for '" + extConfigLocation + "' started ..."); ClassPathXmlApplicationContext extContext = new ClassPathXmlApplicationContext(parentContext); extContext.setId("CleverBus extension nr. " + extNumber); extContext.setDisplayName("CleverBus extension context for '" + extConfigLocation + '"'); extContext.setConfigLocation(extConfigLocation); extContext.refresh(); // add routes into Camel context if (isAutoRouteAdding()) { Map<String, AbstractExtRoute> beansOfType = extContext.getBeansOfType(AbstractExtRoute.class); for (Map.Entry<String, AbstractExtRoute> entry : beansOfType.entrySet()) { AbstractExtRoute route = entry.getValue(); // note: route with existing route ID will override the previous one // it's not possible automatically change route ID before adding to Camel context camelContext.addRoutes(route); }/*from w ww . j a va 2 s . c om*/ } Log.debug("new extension context for '" + extConfigLocation + "' was successfully created"); }
From source file:net.dfs.remote.main.ClientServicesStarter.java
public final void loadNode() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props);// ww w . j a va2 s . c om context.addBeanFactoryPostProcessor(configurer); context.setConfigLocation("net\\dfs\\remote\\filestorage\\spring-client.xml"); context.refresh(); context.start(); /* FileLocationTrackerImpl hash = new FileLocationTrackerImpl(); hash.removeAll(); */ log.info("Client Started"); FileReceiverSupport receiveFile = (FileReceiverSupport) context.getBean("receiveFile"); receiveFile.connectJavaSpace(); receiveFile.retrieveFile(); }
From source file:org.activiti.crystalball.simulator.impl.simulationexecutor.SimulationRunExecuteJobHandler.java
public void execute(JobEntity job, String configuration, SimulationInstanceEntity simulationInstance, CommandContext commandContext) { log.log(Level.INFO, "Starting simulation experiment [" + simulationInstance + "] configuration [" + configuration + "]"); SimulationRunEntity simulationRun = commandContext.getSimulationRunManager() .findSimulationRunWithReferencesById(configuration); SimulationContext.setSimulationRun(simulationRun); //initializeSimulationRun ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( simulationRun.getSimulation().getSimulationConfigUrl()); PropertyPlaceholderConfigurer propConfig = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("simulationRunId", configuration); propConfig.setProperties(properties); appContext.addBeanFactoryPostProcessor(propConfig); appContext.refresh(); SimulationRunHelper runHelper = new NoopSimulationRunHelper(); if (appContext.containsBean("simulationRunHelper")) runHelper = (SimulationRunHelper) appContext.getBean("simulationRunHelper"); try {//from w w w. j av a2s.c o m runHelper.before(configuration); SimulationRun simRun = (SimulationRun) appContext.getBean("simulationRun"); simRun.execute(simulationRun); } catch (Exception e) { log.log(Level.SEVERE, "SimulationRun handling error" + simulationRun, e); } finally { runHelper.after(configuration); appContext.close(); } job.delete(); SimulationContext.removeSimulationRun(); // check whether all jobs for given simulationInstance were already executed. simulationInstance.checkActivity(); log.log(Level.INFO, "finished simulation experiment [" + simulationInstance + "] configuration [" + configuration + "]"); }