List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext addBeanFactoryPostProcessor
@Override public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor)
From source file:pl.bristleback.server.bristle.conf.runner.ServerInstanceResolver.java
public BristlebackServerInstance resolverServerInstance() { InitialConfiguration initialConfiguration = initialConfigurationResolver.resolveConfiguration(); startLogger(initialConfiguration);//ww w. j a v a2 s . c o m AnnotationConfigApplicationContext frameworkContext = new AnnotationConfigApplicationContext(); BristleSpringIntegration springIntegration = new BristleSpringIntegration(actualApplicationContext, frameworkContext); BristlebackBeanFactoryPostProcessor bristlebackPostProcessor = new BristlebackBeanFactoryPostProcessor( initialConfiguration, springIntegration); frameworkContext.addBeanFactoryPostProcessor(bristlebackPostProcessor); frameworkContext.register(SpringConfigurationResolver.class); frameworkContext.scan(InitialConfiguration.SYSTEM_BASE_PACKAGES); frameworkContext.refresh(); BristlebackConfig configuration = frameworkContext.getBean("bristlebackConfigurationFinal", BristlebackConfig.class); return new BristlebackServerInstance(configuration); }
From source file:com.visural.domo.spring.TransactionImplTest.java
private AnnotationConfigApplicationContext springBootstrap(ConnectionSource source) throws BeansException, IllegalStateException { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(AnnotationAwareAspectJAutoProxyCreator.class); CustomScopeConfigurer conf = new CustomScopeConfigurer(); Map<String, Object> scopes = new HashMap<String, Object>(); TransactionScope scope = new TransactionScope(); scopes.put(TransactionScope.Name, scope); conf.setScopes(scopes);/* w w w . j ava 2 s .c o m*/ context.getBeanFactory().registerSingleton("transactionScope", scope); context.addBeanFactoryPostProcessor(conf); context.scan("com.visural"); context.refresh(); context.getBean(TransactionConfig.class).getConnectionProvider().registerDefaultConnectionSource(source); return context; }
From source file:io.gravitee.gateway.handlers.api.ApiContextHandlerFactory.java
AbstractApplicationContext createApplicationContext(Api api) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.setParent(gatewayApplicationContext); context.setClassLoader(new ReactorHandlerClassLoader(gatewayApplicationContext.getClassLoader())); context.setEnvironment((ConfigurableEnvironment) gatewayApplicationContext.getEnvironment()); PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setIgnoreUnresolvablePlaceholders(true); configurer.setEnvironment(gatewayApplicationContext.getEnvironment()); context.addBeanFactoryPostProcessor(configurer); context.getBeanFactory().registerSingleton("api", api); context.register(ApiHandlerConfiguration.class); context.setId("context-api-" + api.getName()); context.refresh();//from ww w. ja va 2 s .c o m return context; }
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); }/*w w w.j a v a2 s . co 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:com.fitbur.testify.integration.SpringIntegrationTest.java
@Override protected Statement methodBlock(FrameworkMethod method) { TestClass testClass = getTestClass(); Class<?> javaClass = testClass.getJavaClass(); Object testInstance;//w w w. j av a 2 s .co m try { testInstance = createTest(); } catch (Exception e) { throw new IllegalStateException(e); } TestContext testContext = getTestContext(javaClass); testContext.setTestInstance(testInstance); String testClassName = testContext.getTestClassName(); AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(); appContext.setId(testClassName); appContext.setAllowBeanDefinitionOverriding(true); appContext.setAllowCircularReferences(false); serviceLocator = new SpringServiceLocator(appContext, serviceAnnotations); methodTestNeeds = new TestNeeds(testContext, method.getName(), NeedScope.METHOD); methodTestNeeds.init(); methodTestNeedContainers = new TestNeedContainers(testContext, method.getName(), NeedScope.METHOD); methodTestNeedContainers.init(); TestCaseInstance testCaseInstance = new TestCaseInstance(method.getName(), testInstance); serviceLocator.addConstant(testCaseInstance.getTestName(), testCaseInstance); SpringServicePostProcessor postProcessor = new SpringServicePostProcessor(serviceLocator, methodTestNeeds, methodTestNeedContainers, classTestNeeds, classTestNeedContainers); appContext.addBeanFactoryPostProcessor(postProcessor); IntegrationTestReifier reifier = new IntegrationTestReifier(testContext, serviceLocator, testInstance); IntegrationTestCreator creator = new IntegrationTestCreator(testContext, reifier, serviceLocator); if (testContext.getCutDescriptor() != null) { creator.cut(); } Set<FieldDescriptor> real = testContext.getFieldDescriptors().values().parallelStream() .filter(p -> !p.getInstance().isPresent()) .filter(p -> p.hasAnnotations(serviceAnnotations.getInjectors())).collect(toSet()); creator.real(real); IntegrationTestVerifier verifier = new IntegrationTestVerifier(testContext, LOGGER); verifier.wiring(); Statement statement = methodInvoker(method, testInstance); statement = possiblyExpectingExceptions(method, testInstance, statement); statement = withBefores(method, testInstance, statement); statement = withAfters(method, testInstance, statement); statement = withRules(method, testInstance, statement); return statement; }