List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext
public GenericApplicationContext()
From source file:net.sourceforge.vulcan.spring.AppCtxTest.java
public void testParentReceivesFromChild() throws Exception { GenericApplicationContext child = new GenericApplicationContext(); child.setParent(this.ac); child.refresh();//from w w w .ja va2 s . com assertNotSame(evt, received); child.publishEvent(evt); assertSame(evt, received); }
From source file:org.brekka.stillingar.spring.converter.ApplicationContextConverter.java
@Override public ApplicationContext convert(Object obj) { Document document = documentConverter.convert(obj); GenericApplicationContext context;/* w w w. j av a 2 s . co m*/ if (applicationContext == null) { context = new GenericApplicationContext(); } else { context = new GenericApplicationContext(applicationContext); } XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.registerBeanDefinitions(document, null); context.refresh(); return context; }
From source file:net.sourceforge.vulcan.spring.SpringEventPoolTest.java
public void testDoesNotHoldUnknownEvents() { assertEquals(0, pool.events.size()); pool.onApplicationEvent(new ContextRefreshedEvent(new GenericApplicationContext())); assertEquals(0, pool.events.size()); }
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/* ww w .j a v 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:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Before public void setupContext() { applicationContext = new GenericApplicationContext(); // add the mapper scanner as a bean definition rather than explicitly setting a // postProcessor on the context so initialization follows the same code path as reading from // an XML config file GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(MapperScannerConfigurer.class); definition.getPropertyValues().add("basePackage", "org.mybatis.spring.mapper"); applicationContext.registerBeanDefinition("mapperScanner", definition); setupSqlSessionFactory("sqlSessionFactory"); // assume support for autowiring fields is added by MapperScannerConfigurer via // org.springframework.context.annotation.ClassPathBeanDefinitionScanner.includeAnnotationConfig }
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 w w. ja va2s .c o 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.vertx.mods.spring.SpringModBase.java
@Override public final void start() { super.start(); // Make sure we're using the correct classloader Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Assert.notNull(getContainer().getConfig(), "config object is null, which can't be good"); String springConfig = getContainer().getConfig().getString("springConfig", "applicationConfig.xml"); // Looks weird but avoids doing this twice below in the if/else block. // the vertx singleton needs to be registered before the context XML // is loaded or annotated @Configuration class is registered. ///*from w w w .j av a2 s . co m*/ // I also like the analogy of the vertx instance being in a parent // context, as it's not instantiated in the context you really use. this.parent = new GenericApplicationContext(); ConfigurableListableBeanFactory factory = parent.getBeanFactory(); factory.registerSingleton("vertx", vertx); parent.refresh(); parent.start(); // Detect whether this app is configured with an XML or @Configuration. if (springConfig.endsWith(".xml")) { this.context = new GenericXmlApplicationContext(); context.setParent(parent); ((GenericXmlApplicationContext) context).load(springConfig); } else { this.context = new AnnotationConfigApplicationContext(); context.setParent(parent); try { Class<?> c = Class.forName(springConfig); ((AnnotationConfigApplicationContext) context).register(c); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } factory = context.getBeanFactory(); BeanPostProcessor vertxSupportProcessor = new VertxAwareBeanPostProcessor(vertx); factory.addBeanPostProcessor(vertxSupportProcessor); beforeStartApplicationContext(); context.refresh(); context.start(); context.registerShutdownHook(); afterStartApplicationContext(); }
From source file:com.github.yihtserns.jaxbean.unmarshaller.api.SpringBeanHandlerTest.java
@Override protected <T> T unmarshal(String xml, Class<T> rootType, Class<?>... allTypes) throws Exception { JaxbeanUnmarshaller unmarshaller = JaxbeanUnmarshaller.newInstance(merge(rootType, allTypes)); final UnmarshallerNamespaceHandler unmarshallerNamespaceHandler = new UnmarshallerNamespaceHandler( unmarshaller);/* www . jav a 2 s . co m*/ GenericApplicationContext appContext = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext) { @Override protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { final NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver(); return new NamespaceHandlerResolver() { public NamespaceHandler resolve(String namespaceUri) { if (namespaceUri.equals("http://example.com/jaxb")) { return unmarshallerNamespaceHandler; } return defaultResolver.resolve(namespaceUri); } }; } }; xmlReader.setValidating(false); xmlReader.loadBeanDefinitions(new InputSource(new StringReader(xml))); appContext.refresh(); return appContext.getBean(rootType); }
From source file:com.sitewhere.configuration.ExternalConfigurationResolver.java
@Override public ApplicationContext resolveSiteWhereContext(IVersion version) throws SiteWhereException { try {//from www. java 2 s.co m String url = getRemoteConfigUrl() + "/sitewhere-server.xml"; LOGGER.info("Loading configuration from external source: " + url); GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); URL remote = new URL(getRemoteConfigUrl()); reader.loadBeanDefinitions(new InputStreamResource(remote.openStream())); context.refresh(); return context; } catch (Exception e) { throw new SiteWhereException(e); } }
From source file:org.apache.ignite.yardstick.IgniteNode.java
/** * @param springCfgPath Spring configuration file path. * @return Grid configuration./* w w w. ja va2 s .co m*/ * @throws Exception If failed. */ protected static IgniteConfiguration loadConfiguration(String springCfgPath) throws Exception { URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = IgniteUtils.resolveIgniteUrl(springCfgPath); if (url == null) throw new IgniteCheckedException("Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to IGNITE_HOME.", e); } GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url)); springCtx.refresh(); } catch (BeansException e) { throw new Exception("Failed to instantiate Spring XML application context [springUrl=" + url + ", err=" + e.getMessage() + ']', e); } Map<String, IgniteConfiguration> cfgMap; try { cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); } catch (BeansException e) { throw new Exception("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null || cfgMap.isEmpty()) throw new Exception("Failed to find ignite configuration in: " + url); return cfgMap.values().iterator().next(); }