@Test public void repro() { ConfigurableApplicationContext parent = new GenericApplicationContext(); parent.refresh(); AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.setParent(parent); child.refresh(); ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class); assertThat("unknown env", env, anyOf( sameInstance(parent.getEnvironment()), sameInstance(child.getEnvironment()))); assertThat("expected child ctx env", env, sameInstance(child.getEnvironment())); child.close(); parent.close(); }
protected AnnotationConfigApplicationContext createContext(String name) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); if (this.configurations.containsKey(name)) { for (Class<?> configuration : this.configurations.get(name) .getConfiguration()) { context.register(configuration); } } for (Map.Entry<String, C> entry : this.configurations.entrySet()) { if (entry.getKey().startsWith("default.")) { for (Class<?> configuration : entry.getValue().getConfiguration()) { context.register(configuration); } } } context.register(PropertyPlaceholderAutoConfiguration.class, this.defaultConfigType); context.getEnvironment().getPropertySources().addFirst(new MapPropertySource( this.propertySourceName, Collections.<String, Object> singletonMap(this.propertyName, name))); if (this.parent != null) { // Uses Environment from parent as well as beans context.setParent(this.parent); } context.setDisplayName(generateDisplayName(name)); context.refresh(); return context; }
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.getId()); context.refresh(); return context; }
@Test public void testParentChildAnnotationConfigurationFromAnotherPackage() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(org.springframework.integration.configuration2.ChildConfiguration.class); child.setParent(this.context); child.refresh(); AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
@Test public void testParentChildAnnotationConfiguration() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(ChildConfiguration.class); child.setParent(this.context); child.refresh(); AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
@Before public void clear() { this.registry.expireUnusedOlderThan(0); this.client.close(); this.child = new AnnotationConfigApplicationContext(); this.child.register(DefaultLockRepository.class); this.child.setParent(this.context); this.child.refresh(); }
private static AnnotationConfigApplicationContext getAnnotationConfigApplicationContext( Class<?> springConfigClass, GenericApplicationContext genericApplicationContext) { AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(); annotationConfigApplicationContext.setParent(genericApplicationContext); annotationConfigApplicationContext.register(SpringContextConfiguration.class, springConfigClass); return annotationConfigApplicationContext; }
public static AnnotationConfigApplicationContext initBatchContext(ApplicationContext baseContext) { //ApplicationContext baseContext = initBaseContext(); //AnnotationConfigApplicationContext baseContext = new AnnotationConfigApplicationContext(ConfigBatchJobDynamic.class); //AnnotationConfigApplicationContext x = new AnnotationConfigApplicationContext() // GenericApplicationContext batchContext = new GenericApplicationContext(baseContext); // AnnotationConfigUtils.registerAnnotationConfigProcessors(batchContext); AnnotationConfigApplicationContext batchContext = new AnnotationConfigApplicationContext(); batchContext.setParent(baseContext); copyScopes(batchContext, (GenericApplicationContext)baseContext); return batchContext; }
static void scanHandler() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.setParent(CTX); context.scan("com.mpush.mpns.web.handler"); context.refresh(); }
public static ApplicationContext initBaseContext(ApplicationContext appContext) { AnnotationConfigApplicationContext coreContext = new AnnotationConfigApplicationContext(); //if(appContext != null) { coreContext.setParent(appContext); //} coreContext.register(ConfigParsersCore.class); coreContext.refresh(); AnnotationConfigApplicationContext baseContext = new AnnotationConfigApplicationContext(); baseContext.setParent(coreContext); baseContext.register(ConfigBatchJobDynamic.class); baseContext.refresh(); return baseContext; }
protected AbstractApplicationContext getAnnotationContext(SpringContext context, ConfigurableApplicationContext parent) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); if (parent != null) { ctx.setParent(parent); } else { addMetaInfo(ctx, context); } for (Class<?> annotatedClass : context.getAnnotatedClasses()) { ctx.register(annotatedClass); } return ctx; }
protected AnnotationConfigApplicationContext getAnnotationContext(SpringContext context, ConfigurableApplicationContext parent) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); if (parent != null) { ctx.setParent(parent); } else { addMetaInfo(ctx, context); } for (Class<?> annotatedClass : context.getAnnotatedClasses()) { ctx.register(annotatedClass); } return ctx; }
@Configuration @ComponentScan public class TaskConfig {} public interface TaskFactory { Task createTask(); } @Component public class TaskFactoryImpl implements TaskFactory { private ApplicationContext parentContext; @Autowired public void setParentContext(ApplicationContext parentContext) { this.parentContext = parentContext; } @Override public Task createTask() { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { context.register(TaskConfig.class); context.setParent(parentContext); context.refresh(); return context.getBean(Task.class); } } }
public ApplicationContext getObject() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.setParent(parent); context.scan(packages); context.refresh();
public Job processJob(Map<String, Object> data) throws Exception { // Check if there is a context associated with the job Object context = data.get(ContextProcessorJsonUtils.ATTR_CONTEXT); AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext(); c.setParent(mainContext); ContextProcessorJsonUtils.processContext(c, context, new HashMap<String, String>()); c.refresh(); JobBuilderFactory jobBuilders = config.jobBuilders(); processStep(null, data); JobBuilder jobBuilder = jobBuilders.get("sparqlExportJob"); // Process the job context and the step context SimpleJobBuilder x = jobBuilder.start((Step)null); return null; }
public void setUp() { AnnotationConfigApplicationContext testCtx = new AnnotationConfigApplicationContext(); testCtx.setParent(this.appCtx); testCtx.register(RealTestCfg.class); testCtx.refresh();
@Override public void configure(ConfigurationContext ctx) { // Application context for autowiring. AnnotationConfigApplicationContext autowireCtx = new AnnotationConfigApplicationContext() { @Override public String toString() { return SpringInjectionService.class.getSimpleName() + "Context"; } }; // Expose services for autowiring. ConfigurableListableBeanFactory factory = autowireCtx.getBeanFactory(); uniqueServices(ctx).forEach(service -> { factory.registerResolvableDependency(service.getClass(), service); for (Class<?> type : service.getClass().getInterfaces()) { factory.registerResolvableDependency(type, service); } }); autowireCtx.refresh(); autowireCtx.setParent(parentCtx); autowire = autowireCtx.getAutowireCapableBeanFactory(); }
@Deprecated public static List<PropertySource<?>> getPropertySources(Class<?> annotatedClass, String propertiesBeanName, Properties properties, List<String> activeProfiles, List<String> defaultProfiles) { ConfigurableApplicationContext parent = null; if (properties == null) { parent = getConfigurableApplicationContext(); } else { parent = getContextWithPreRegisteredBean(propertiesBeanName, properties); } AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.setParent(parent); setupProfiles(child, activeProfiles, defaultProfiles); child.register(annotatedClass); child.refresh(); return getPropertySources(child); }
AbstractApplicationContext createApplicationContext(Domain domain) { 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("domain", domain); context.register(HandlerConfiguration.class); context.setId("context-domain-" + domain.getId()); context.refresh(); return context; }
AbstractApplicationContext createApplicationContext(Domain domain) { 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("domain", domain); context.register(HandlerConfiguration.class); context.setId("context-domain-" + domain.getId()); context.refresh(); return context; }