org.springframework.context.annotation.AnnotationConfigApplicationContext.setParent()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.setParent()方法的一些代码示例,展示了AnnotationConfigApplicationContext.setParent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationConfigApplicationContext.setParent()方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotationConfigApplicationContext
类名称:AnnotationConfigApplicationContext
方法名:setParent

AnnotationConfigApplicationContext.setParent介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

@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();
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-context

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;
}

代码示例来源:origin: gravitee-io/gravitee-gateway

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;
}

代码示例来源:origin: spring-projects/spring-integration

@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();
}

代码示例来源:origin: spring-projects/spring-integration

@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();
}

代码示例来源:origin: spring-projects/spring-integration

@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();
}

代码示例来源:origin: amoAHCP/spring-vertx-ext

private static AnnotationConfigApplicationContext getAnnotationConfigApplicationContext(
  Class<?> springConfigClass, GenericApplicationContext genericApplicationContext) {
  AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
  annotationConfigApplicationContext.setParent(genericApplicationContext);
  annotationConfigApplicationContext.register(SpringContextConfiguration.class, springConfigClass);
  return annotationConfigApplicationContext;
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

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;
  }

代码示例来源:origin: mpusher/mpns

static void scanHandler() {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
  context.setParent(CTX);
  context.scan("com.mpush.mpns.web.handler");
  context.refresh();
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

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;
}

代码示例来源:origin: org.kuali.common/kuali-util

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;
}

代码示例来源:origin: org.kuali.common/kuali-util

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;
}

代码示例来源:origin: stackoverflow.com

@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);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public ApplicationContext getObject() throws Exception {
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
  context.setParent(parent);
  context.scan(packages);
  context.refresh();

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

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;
}

代码示例来源:origin: stackoverflow.com

public void setUp() {
  AnnotationConfigApplicationContext testCtx = new AnnotationConfigApplicationContext();
  testCtx.setParent(this.appCtx);
  testCtx.register(RealTestCfg.class);
  testCtx.refresh();

代码示例来源:origin: io.hekate/hekate-spring

@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();
}

代码示例来源:origin: org.kuali.common/kuali-util

@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);
}

代码示例来源:origin: io.gravitee.am.gateway.handlers/gravitee-am-gateway-handler

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;
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

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;
}

相关文章

微信公众号

最新文章

更多

AnnotationConfigApplicationContext类方法