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

x33g5p2x  于2022-01-18 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(107)

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

ConfigurableApplicationContext.setParent介绍

[英]Set the parent of this application context.

Note that the parent shouldn't be changed: It should only be set outside a constructor if it isn't available when an object of this class is created, for example in case of WebApplicationContext setup.
[中]设置此应用程序上下文的父级。
请注意,不应更改父级:只有在创建此类的对象时父级不可用时,才应在构造函数外部设置父级,例如在WebApplicationContext设置的情况下。

代码示例

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

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
  if (applicationContext != this.parent) {
    applicationContext.setParent(this.parent);
    applicationContext.addApplicationListener(EventPublisher.INSTANCE);
  }
}

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

@Test
public void loadConfigWhenMultipleWebSecurityConfigurationThenContextLoads() throws Exception {
  this.spring.register(ParentConfig.class).autowire();
  this.child.register(ChildConfig.class);
  this.child.getContext().setParent(this.spring.getContext());
  this.child.autowire();
  assertThat(this.spring.getContext().getBean("springSecurityFilterChain")).isNotNull();
  assertThat(this.child.getContext().getBean("springSecurityFilterChain")).isNotNull();
  assertThat(this.spring.getContext().containsBean("springSecurityFilterChain")).isTrue();
  assertThat(this.child.getContext().containsBean("springSecurityFilterChain")).isTrue();
}

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

@Test
  public void refreshContextWhenParentAndChildRegisteredThenNoException() {
    this.parent.register(Sec2377AConfig.class).autowire();

    ConfigurableApplicationContext context =
      this.child.register(Sec2377BConfig.class).getContext();
    context.setParent(this.parent.getContext());

    this.child.autowire();
  }
}

代码示例来源:origin: mulesoft/mule

private void createRegistryWithParentContext(MuleContext muleContext, ApplicationContext applicationContext,
                       ApplicationContext parentContext)
  throws ConfigurationException {
 if (applicationContext instanceof ConfigurableApplicationContext) {
  ((ConfigurableApplicationContext) applicationContext).setParent(parentContext);
  registry = new SpringRegistry(applicationContext, muleContext, muleArtifactContext.getDependencyResolver(),
                 ((DefaultMuleContext) muleContext).getLifecycleInterceptor());
 } else {
  throw new ConfigurationException(I18nMessageFactory
    .createStaticMessage("Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext"));
 }
}

代码示例来源:origin: org.springframework.boot/spring-boot-test

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
  applicationContext.setParent(this.parent);
}

代码示例来源:origin: NationalSecurityAgency/datawave

@Override
public void setParent(ApplicationContext parent) {
  lock.writeLock().lock();
  try {
    configurableApplicationContext.setParent(parent);
  } finally {
    lock.writeLock().unlock();
  }
}

代码示例来源:origin: org.mule.modules/mule-module-spring-config

public SpringRegistry(ConfigurableApplicationContext applicationContext, ApplicationContext parentContext, MuleContext muleContext)
{
  super(REGISTRY_ID, muleContext);
  applicationContext.setParent(parentContext);
  setApplicationContext(applicationContext);
}

代码示例来源:origin: org.mule.modules/mule-module-spring-config

public SpringRegistry(String id, ConfigurableApplicationContext applicationContext, ApplicationContext parentContext, MuleContext muleContext)
{
  super(id, muleContext);
  applicationContext.setParent(parentContext);
  setApplicationContext(applicationContext);
}

代码示例来源:origin: com.gitlab.spacetrucker/modular-spring-contexts

/**
 * Creates and starts a module based on a bean xml configuration.
 * <p>
 * The {@code moduleRootConfig} spring xml context definition is intended to
 * only contain the definitions of the root modules and their dependencies
 * amongst each other.
 * 
 * @param moduleRootConfig
 *            from which the root module is created
 * @return the newly created module
 */
public static ConfigurableApplicationContext startModules(String moduleRootConfig) {
  @SuppressWarnings("resource")
  GenericApplicationContext moduleRootContext = new GenericApplicationContext();
  AbstractBeanDefinition moduleRootBeanDefinition = ModularSpringContextsModuleBeanDefinitionParser
      .createBeanDefinition(Collections.singletonList(moduleRootConfig), Collections.<String>emptyList(),
          null);
  moduleRootContext.registerBeanDefinition("moduleRoot", moduleRootBeanDefinition);
  moduleRootContext.refresh();
  ConfigurableApplicationContext moduleRoot = moduleRootContext.getBean("moduleRoot",
      ConfigurableApplicationContext.class);
  moduleRoot.setParent(null);
  return moduleRoot;
}

代码示例来源:origin: org.springframework.boot/spring-boot-test

private void configureContext(C context) {
  if (this.parent != null) {
    context.setParent(this.parent);
  }
  if (this.classLoader != null) {
    Assert.isInstanceOf(DefaultResourceLoader.class, context);
    ((DefaultResourceLoader) context).setClassLoader(this.classLoader);
  }
  this.environmentProperties.applyTo(context);
  Class<?>[] classes = Configurations.getClasses(this.configurations);
  if (classes.length > 0) {
    ((AnnotationConfigRegistry) context).register(classes);
  }
  this.initializers.forEach((initializer) -> initializer.initialize(context));
  context.refresh();
}

代码示例来源:origin: org.mule.runtime/mule-module-spring-config

private void createRegistryWithParentContext(MuleContext muleContext, ApplicationContext applicationContext,
                       ApplicationContext parentContext)
  throws ConfigurationException {
 if (applicationContext instanceof ConfigurableApplicationContext) {
  ((ConfigurableApplicationContext) applicationContext).setParent(parentContext);
  registry = new SpringRegistry(applicationContext, muleContext, muleArtifactContext.getDependencyResolver(),
                 ((DefaultMuleContext) muleContext).getLifecycleInterceptor());
 } else {
  throw new ConfigurationException(I18nMessageFactory
    .createStaticMessage("Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext"));
 }
}

代码示例来源:origin: com.foreach.across/across-core

currentApplicationContext.setParent( parentApplicationContext );
currentBeanFactory.setParentBeanFactory( parentBeanFactory );
parent.setParent( parentApplicationContext );
parent.getBeanFactory().setParentBeanFactory( parentBeanFactory );

相关文章

微信公众号

最新文章

更多

ConfigurableApplicationContext类方法