/** * Refresh this servlet's application context, as well as the dependent state of the servlet. * * @see #getWebApplicationContext() * @see org.springframework.context.ConfigurableApplicationContext#refresh() */ public void refresh() { WebApplicationContext wac = getWebApplicationContext(); if (!(wac instanceof ConfigurableApplicationContext)) { throw new IllegalStateException("WebApplicationContext does not support refresh: " + wac); } ((ConfigurableApplicationContext) wac).refresh(); }
protected void initClassPathApplicationContext( AcServiceConfig serviceConfig, String... configLocations) { appContext = new ClassPathXmlApplicationContext( configLocations, false, prepareParentContext(serviceConfig)); postSetupApplicationContext(appContext, serviceConfig); appContext.refresh(); }
void configure(Object beanInstance) { // check the ApplicationContext states first , and call the refresh if necessary if (((SpringCamelContext) getCamelContext()).getApplicationContext() instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext context = (ConfigurableApplicationContext) ((SpringCamelContext) getCamelContext()).getApplicationContext(); if (!context.isActive()) { context.refresh(); } } configurer.configureBean(beanId, beanInstance); }
protected void initXmlApplicationContext( AcServiceConfig serviceConfig, boolean autoScan, Resource... configResources) { GenericXmlApplicationContext xmlContext = new GenericXmlApplicationContext(); appContext = xmlContext; xmlContext.setParent(prepareParentContext(serviceConfig)); xmlContext.load(configResources); if (autoScan) { ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(xmlContext); // scan this package from provider hosting scanner.scan(this.getClass().getPackage().getName()); } postSetupApplicationContext(appContext, serviceConfig); appContext.refresh(); }
/** * create a component manager based on a list of component.xml * * @param configPaths a ';' seperated list of xml bean config files * @throws IOException */ public TestComponentManagerContainer(String configPaths) throws IOException { // we assume that all the jars are in the same classloader, so this will // not check for // incorrect bindings and will not fully replicate the tomcat // experience, but is an easier environment // to work within for kernel testing. // For a more complex structure we could use the kernel poms in the repo // to generate the dep list. if (ComponentManager.m_componentManager != null) { log.info("Closing existing Component Manager "); /* try { ComponentManager.m_componentManager.close(); } catch ( Throwable t ) { log.warn("Close Failed with message, safe to ignore "+t.getMessage()); } */ log.info("Closing Complete "); ComponentManager.m_componentManager = null; } log.info("Starting Component Manager with [" + configPaths + "]"); ComponentManager.setLateRefresh(true); componentManager = (SpringCompMgr) ComponentManager.getInstance(); ConfigurableApplicationContext ac = componentManager.getApplicationContext(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // we could take the kernel bootstrap from from the classpath in future // rather than from // the filesystem List<Resource> config = new ArrayList<Resource>(); String[] configPath = configPaths.split(";"); for (String p : configPath) { File xml = new File(p); config.add(new FileSystemResource(xml.getCanonicalPath())); } loadComponent(ac, config, classLoader); ac.refresh(); log.debug("Finished starting the component manager"); // TODO Auto-generated constructor stub }
@Override public void start() { this.context = new ClassPathXmlApplicationContext(new String[] {CORE_CONFIG, PLUGIN_CONFIGS}, false); context.setId(this.id); updateLoggerFilename(); Assert.notNull(launcherContext, "no Container launcher ApplicationContext has been set"); ApplicationContext globalContext = launcherContext.getParent(); Assert.notNull(globalContext, "no global context has been set"); context.setParent(globalContext); context.registerShutdownHook(); context.refresh(); this.containerRunning = true; context.publishEvent(new ContainerStartedEvent(this)); if (logger.isInfoEnabled()) { logger.info("started container: " + context.getId()); } }
public static void main(String[] args) throws InterruptedException { final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("/spring/service-context.xml"); System.out.println("Spring Integration Demo"); applicationContext.refresh(); applicationContext.start(); try { LOG.info("Starting context!"); applicationContext.getBean("launcherService", Runnable.class).run(); // sleep for a while before close to let all the pending message be processed Thread.sleep(500); LOG.info("Going to stop now!"); } finally { applicationContext.close(); } }
public static void refresh() { if (_ctx != null && _ctx instanceof ConfigurableApplicationContext) ((ConfigurableApplicationContext) _ctx).refresh(); else initContext(); }