List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext
public GenericApplicationContext()
From source file:com.sitewhere.configuration.TomcatConfigurationResolver.java
@Override public ApplicationContext resolveSiteWhereContext(IVersion version) throws SiteWhereException { LOGGER.info("Loading Spring configuration ..."); File sitewhereConf = getSiteWhereConfigFolder(); File serverConfigFile = new File(sitewhereConf, SERVER_CONFIG_FILE_NAME); if (!serverConfigFile.exists()) { throw new SiteWhereException( "SiteWhere server configuration not found: " + serverConfigFile.getAbsolutePath()); }//from w ww . j av a2s .c o m GenericApplicationContext context = new GenericApplicationContext(); // Plug in custom property source. Map<String, Object> properties = new HashMap<String, Object>(); properties.put("sitewhere.edition", version.getEditionIdentifier().toLowerCase()); MapPropertySource source = new MapPropertySource("sitewhere", properties); context.getEnvironment().getPropertySources().addLast(source); // Read context from XML configuration file. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new FileSystemResource(serverConfigFile)); context.refresh(); return context; }
From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinderTest.java
@Before public void setUp() throws Exception { final HermesResponse response = HermesResponseBuilder.hermesResponse().withHttpStatus(201).build(); when(hermesSender.send(any(URI.class), any(HermesMessage.class))) .thenReturn(CompletableFuture.completedFuture(response)); binder = new HermesClientBinder(HermesClientBuilder.hermesClient(hermesSender).build()); binder.setApplicationContext(new GenericApplicationContext()); }
From source file:org.uimafit.spring.SpringContextResourceManagerTest.java
private ApplicationContext getApplicationContext() { final GenericApplicationContext ctx = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx); ctx.registerBeanDefinition("springBean", BeanDefinitionBuilder.genericBeanDefinition(String.class) .addConstructorArgValue("BEAN").getBeanDefinition()); ctx.refresh();/* ww w.j a va 2s . c om*/ return ctx; }
From source file:com.obergner.hzserver.Main.java
void start() throws Exception { enableHangupSupport();//ww w. j av a 2s . c om this.serverInfo.logBootStart(); final GenericApplicationContext ctx = new GenericApplicationContext(); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions("classpath:META-INF/spring/hz-server-main-context.xml", "classpath*:META-INF/spring/hz-cache-context.xml"); ctx.registerShutdownHook(); ctx.addApplicationListener(new ApplicationListener<ContextRefreshedEvent>() { @Override public void onApplicationEvent(final ContextRefreshedEvent event) { Main.this.serverInfo.logBootCompleted(); } }); ctx.addApplicationListener(new ApplicationListener<ContextStoppedEvent>() { @Override public void onApplicationEvent(final ContextStoppedEvent event) { Main.this.serverInfo.logShutdownCompleted(); } }); ctx.refresh(); }
From source file:org.jacpfx.vertx.spring.SpringVerticleFactory.java
private Verticle createSpringVerticle(final Class<?> currentVerticleClass, ClassLoader classLoader) { final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class); final Class<?> springConfigClass = annotation.springConfig(); // Create the parent context final GenericApplicationContext genericApplicationContext = new GenericApplicationContext(); genericApplicationContext.setClassLoader(classLoader); if (parentContext != null) { genericApplicationContext.setParent(parentContext); }/*from w w w . j a va 2 s . c o m*/ genericApplicationContext.refresh(); genericApplicationContext.start(); // 1. Create a new context for each verticle and use the specified spring configuration class if possible AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(); annotationConfigApplicationContext.setParent(genericApplicationContext); annotationConfigApplicationContext.register(SpringContextConfiguration.class, springConfigClass); // 2. Register a bean definition for this verticle annotationConfigApplicationContext.registerBeanDefinition(currentVerticleClass.getSimpleName(), new VerticleBeanDefinition(currentVerticleClass)); // 3. Add a bean factory post processor to avoid configuration issues annotationConfigApplicationContext .addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass)); annotationConfigApplicationContext.refresh(); annotationConfigApplicationContext.start(); annotationConfigApplicationContext.registerShutdownHook(); // 5. Return the verticle by fetching the bean from the context return (Verticle) annotationConfigApplicationContext.getBeanFactory() .getBean(currentVerticleClass.getSimpleName()); }
From source file:edu.internet2.middleware.psp.util.PSPUtil.java
public static GenericApplicationContext createSpringContext(List<Resource> resources) throws ResourceException { GenericApplicationContext gContext = new GenericApplicationContext(); SpringConfigurationUtils.populateRegistry(gContext, resources); gContext.refresh();/*from w w w . j av a 2 s.co m*/ gContext.registerShutdownHook(); return gContext; }
From source file:de.hybris.platform.core.TenantRestartTest.java
@Override @Before/*from w ww. j av a 2s.c om*/ public void setUp() throws Exception { final ApplicationContext parent = Registry.getCoreApplicationContext(); applicationContext = new GenericApplicationContext(); applicationContext.setParent(parent); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); xmlReader.loadBeanDefinitions(new ByteArrayResource(MESSAGE_LISTENER_DEF.getBytes())); applicationContext.refresh(); testListener = applicationContext.getBean(TestAfterTenantStartupEventListener.class); Assertions.assertThat(testListener).isInstanceOf(TestAfterTenantStartupEventListener.class); super.setUp(); }
From source file:nz.co.senanque.madura.bundle.BundleRootImpl.java
public void init(DefaultListableBeanFactory ownerBeanFactory, Properties properties, ClassLoader cl, Map<String, Object> inheritableBeans) { m_properties = properties;/*from ww w . ja v a 2 s. c o m*/ m_inheritableBeans = inheritableBeans; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(cl); m_classLoader = cl; GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); String contextPath = properties.getProperty("Bundle-Context", "/bundle-spring.xml"); m_logger.debug("loading context: {}", contextPath); ClassPathResource classPathResource = new ClassPathResource(contextPath, cl); xmlReader.loadBeanDefinitions(classPathResource); PropertyPlaceholderConfigurer p = new PropertyPlaceholderConfigurer(); p.setProperties(properties); ctx.addBeanFactoryPostProcessor(p); if (m_logger.isDebugEnabled()) { dumpClassLoader(cl); } for (Map.Entry<String, Object> entry : inheritableBeans.entrySet()) { BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder .genericBeanDefinition(InnerBundleFactory.class); beanDefinitionBuilder.addPropertyValue("key", entry.getKey()); beanDefinitionBuilder.addPropertyValue("object", inheritableBeans.get(entry.getKey())); ctx.registerBeanDefinition(entry.getKey(), beanDefinitionBuilder.getBeanDefinition()); } Scope scope = ownerBeanFactory.getRegisteredScope("session"); if (scope != null) { ctx.getBeanFactory().registerScope("session", scope); } ctx.refresh(); m_applicationContext = ctx; Thread.currentThread().setContextClassLoader(classLoader); }
From source file:org.uimafit.spring.UimaFactoryInjectionTest.java
private ApplicationContext getApplicationContext() { final GenericApplicationContext ctx = new GenericApplicationContext(); AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx); ctx.registerBeanDefinition("otherBean", BeanDefinitionBuilder.genericBeanDefinition(String.class) .addConstructorArgValue("BEAN").getBeanDefinition()); ctx.registerBeanDefinition("analysisEngineFactory", BeanDefinitionBuilder.genericBeanDefinition(AnalysisEngineFactory_impl.class).getBeanDefinition()); ctx.registerBeanDefinition("casConsumerFactory", BeanDefinitionBuilder.genericBeanDefinition(CasConsumerFactory_impl.class).getBeanDefinition()); ctx.registerBeanDefinition("casInitializerFactory", BeanDefinitionBuilder.genericBeanDefinition(CasInitializerFactory_impl.class).getBeanDefinition()); ctx.registerBeanDefinition("collectionReaderFactory", BeanDefinitionBuilder .genericBeanDefinition(CollectionReaderFactory_impl.class).getBeanDefinition()); ctx.registerBeanDefinition("customResourceFactory", BeanDefinitionBuilder.genericBeanDefinition(CustomResourceFactory_impl.class).getBeanDefinition()); ctx.refresh();// www. j a v a 2 s . co m return ctx; }
From source file:org.megam.deccanplato.provider.crm.test.ZohoInvoiceAdapterTest.java
@Test public void zohoInvoice() { List<String> functionList = new ArrayList<String>(); functionList.add("expensecategory"); functionList.add("expense"); functionList.add("item"); functionList.add("payment"); List<String> customerList = new ArrayList<String>(); customerList.add("create"); customerList.add("list"); customerList.add("update"); customerList.add("delete"); customerList.add("view"); List<String> invoiceList = new ArrayList<String>(); invoiceList.add("create"); invoiceList.add("list"); invoiceList.add("update"); invoiceList.add("delete"); invoiceList.add("convert"); invoiceList.add("pdf"); invoiceList.add("remind"); invoiceList.add("send"); List<String> estimateList = new ArrayList<String>(); estimateList.add("create"); estimateList.add("list"); estimateList.add("update"); estimateList.add("delete"); estimateList.add("pdf"); estimateList.add("send"); estimateList.add("mark"); List<String> busiActivity = new ArrayList<String>(); busiActivity.add("create"); busiActivity.add("list"); busiActivity.add("update"); busiActivity.add("delete"); GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml")); ctx.refresh();/*from ww w.j a va2s. co m*/ ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry"); for (String function : functionList) { for (String activity : busiActivity) { CommonTest ctest = new CommonTest(); RequestData reqData; reqData = ctest.commonTest(function, activity, ZOHOINVOICE); if (function.equals("user") && activity.equals("create")) { testAdapterAccess(reqData); } ctest.testBusinessImpl(); } } for (int i = 0; i < 1; i++) { String function = "customer"; for (String activity : customerList) { CommonTest ctest = new CommonTest(); RequestData reqData; reqData = ctest.commonTest(function, activity, ZOHOINVOICE); if (function.equals("custoer") && activity.equals("create")) { testAdapterAccess(reqData); } ctest.testBusinessImpl(); } } for (int i = 0; i < 1; i++) { String function = "invoice"; for (String activity : invoiceList) { CommonTest ctest = new CommonTest(); RequestData reqData; reqData = ctest.commonTest(function, activity, ZOHOINVOICE); if (function.equals("invoice") && activity.equals("create")) { testAdapterAccess(reqData); } ctest.testBusinessImpl(); } } for (int i = 0; i < 1; i++) { String function = "estimate"; for (String activity : estimateList) { CommonTest ctest = new CommonTest(); RequestData reqData; reqData = ctest.commonTest(function, activity, ZOHOINVOICE); if (function.equals("estimate") && activity.equals("create")) { testAdapterAccess(reqData); } ctest.testBusinessImpl(); } } }