List of usage examples for org.springframework.context.support GenericApplicationContext refresh
@Override public void refresh() throws BeansException, IllegalStateException
From source file:org.jboss.fuse.wsdl2rest.util.SpringCamelContextFactory.java
private static List<SpringCamelContext> createCamelContextList(Resource resource, ClassLoader classLoader) throws Exception { if (classLoader == null) classLoader = SpringCamelContextFactory.class.getClassLoader(); GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(classLoader); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext) { @Override/* w w w . jav a2 s.c o m*/ protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver(); return new CamelNamespaceHandlerResolver(defaultResolver); } }; xmlReader.loadBeanDefinitions(resource); SpringCamelContext.setNoStart(true); appContext.refresh(); List<SpringCamelContext> result = new ArrayList<>(); for (String name : appContext.getBeanNamesForType(SpringCamelContext.class)) { result.add(appContext.getBean(name, SpringCamelContext.class)); } return Collections.unmodifiableList(result); }
From source file:com.mitre.cockpits.cmscockpit.CmsCockpitConfigurationTest.java
@BeforeClass public static void testsSetup() { Registry.setCurrentTenantByID("junit"); final GenericApplicationContext context = new GenericApplicationContext(); context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader())); context.setClassLoader(Registry.class.getClassLoader()); context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader()); context.setParent(Registry.getGlobalApplicationContext()); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.setBeanClassLoader(Registry.class.getClassLoader()); xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class); xmlReader.loadBeanDefinitions(getSpringConfigurationLocations()); context.refresh(); applicationContext = context;//from ww w .ja va2 s . co m }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
public static GenericApplicationContext getSpringApplicationContextClassPath(ClassLoader classLoader, String relPath) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(classLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try {/* w w w. j a va 2s . c o m*/ Thread.currentThread().setContextClassLoader(classLoader); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); InputStream in = classLoader.getResourceAsStream(relPath); if (in == null) { throw new AxisFault("Spring context cannot be located for AxisService"); } xbdr.loadBeanDefinitions(new InputStreamResource(in)); appContext.refresh(); } catch (Exception e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; }
From source file:edu.berkeley.compbio.ncbitaxonomy.service.NcbiTaxonomyServicesContextFactory.java
public static ApplicationContext makeNcbiTaxonomyServicesContext() throws IOException { File propsFile = PropertiesUtils.findPropertiesFile("NCBI_TAXONOMY_SERVICE_PROPERTIES", ".ncbitaxonomy", "service.properties"); logger.debug("Using properties file: " + propsFile); Properties p = new Properties(); FileInputStream is = null;// w w w .ja va 2 s .co m try { is = new FileInputStream(propsFile); p.load(is); } finally { is.close(); } String dbName = (String) p.get("default"); Map<String, Properties> databases = PropertiesUtils.splitPeriodDelimitedProperties(p); GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("ncbitaxonomyclient.xml")); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties properties = databases.get(dbName); if (properties == null) { logger.error("Service definition not found: " + dbName); logger.error("Valid names: " + StringUtils.join(databases.keySet().iterator(), ", ")); throw new NcbiTaxonomyRuntimeException("Database definition not found: " + dbName); } cfg.setProperties(properties); ctx.addBeanFactoryPostProcessor(cfg); ctx.refresh(); // add a shutdown hook for the above context... ctx.registerShutdownHook(); return ctx; }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
public static GenericApplicationContext getSpringApplicationContext(String applicationContxtFilePath, ClassLoader springBeansClassLoader) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(springBeansClassLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try {//from w ww . j a v a2 s. co m // Save the class loader so that you can restore it later Thread.currentThread().setContextClassLoader( new MultiParentClassLoader(new URL[] {}, new ClassLoader[] { springBeansClassLoader, prevCl })); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); xbdr.loadBeanDefinitions( new InputStreamResource(new FileInputStream(new File(applicationContxtFilePath)))); appContext.refresh(); } catch (FileNotFoundException e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
/** * Method to get the spring application context for a spring service * * @param axisService - spring service//from ww w .j a va 2 s. c o m * @param contextLocation - location of the application context file * @return - GenericApplicationContext for the given spring service * @throws AxisFault */ public static GenericApplicationContext getSpringApplicationContext(AxisService axisService, String contextLocation) throws AxisFault { Parameter appContextParameter = axisService.getParameter(SPRING_APPLICATION_CONTEXT); if (appContextParameter != null) { return (GenericApplicationContext) appContextParameter.getValue(); } else { GenericApplicationContext appContext = new GenericApplicationContext(); ClassLoader classLoader = axisService.getClassLoader(); appContext.setClassLoader(classLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); InputStream in = classLoader.getResourceAsStream(contextLocation); if (in == null) { throw new AxisFault("Spring context cannot be located for AxisService"); } xbdr.loadBeanDefinitions(new InputStreamResource(in)); appContext.refresh(); axisService.addParameter(new Parameter(SPRING_APPLICATION_CONTEXT, appContext)); } catch (Exception e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; } }
From source file:net.sourceforge.vulcan.spring.AppCtxTest.java
public void testChildDoesNotReceiveFromParent() throws Exception { GenericApplicationContext parent = new GenericApplicationContext(); parent.refresh(); ac.setParent(parent);/* ww w . j a v a 2 s. co m*/ assertNotSame(evt, received); parent.publishEvent(evt); assertNotSame(evt, received); }
From source file:org.alfresco.cacheserver.dropwizard.Application.java
public void start() { if (springContextFileLocation != null) { // parent spring context with the normal DropWizard configuration defined GenericApplicationContext parent = new GenericApplicationContext(); parent.refresh(); parent.getBeanFactory().registerSingleton("configuration", this); parent.registerShutdownHook();/* ww w . j a v a 2s . c o m*/ parent.start(); try { PropertyPlaceholderConfigurer configurer = loadSpringConfigurer(yamlConfigFileLocation); // child spring context from xml context = new ClassPathXmlApplicationContext(parent); if (configurer != null) { context.addBeanFactoryPostProcessor(configurer); } context.setConfigLocations(new String[] { springContextFileLocation }); context.registerShutdownHook(); context.refresh(); } catch (IOException e) { throw new IllegalStateException("Could not create Spring context", e); } } else { throw new IllegalArgumentException("Spring context file location not set"); } }
From source file:com.textocat.textokit.eval.EvaluationLauncher.java
public static void runUsingProperties(Properties configProperties) throws Exception { GenericApplicationContext appCtx = new GenericApplicationContext(); appCtx.getEnvironment().getPropertySources() .addLast(new PropertiesPropertySource("configFile", configProperties)); XmlBeanDefinitionReader xmlBDReader = new XmlBeanDefinitionReader(appCtx); xmlBDReader.loadBeanDefinitions(APP_CONTEXT_LOCATION); // register listeners Map<String, String> listenerImpls = getPrefixedKeyPairs(configProperties, PREFIX_LISTENER_ID); for (String listenerId : listenerImpls.keySet()) { String listenerClass = listenerImpls.get(listenerId); BeanDefinitionBuilder bb = genericBeanDefinition(listenerClass); Map<String, String> listenerProperties = getPrefixedKeyPairs(configProperties, PREFIX_LISTENER_PROPERTY + listenerId + "."); for (String propName : listenerProperties.keySet()) { bb.addPropertyValue(propName, listenerProperties.get(propName)); }//from w ww. jav a 2 s. c om appCtx.registerBeanDefinition(listenerId, bb.getBeanDefinition()); } appCtx.refresh(); appCtx.registerShutdownHook(); GoldStandardBasedEvaluation eval = appCtx.getBean(GoldStandardBasedEvaluation.class); eval.run(); }
From source file:net.sourceforge.vulcan.spring.AppCtxTest.java
public void testParentReceivesFromChild() throws Exception { GenericApplicationContext child = new GenericApplicationContext(); child.setParent(this.ac); child.refresh(); assertNotSame(evt, received);//w w w . j a v a 2s. com child.publishEvent(evt); assertSame(evt, received); }