|
|
@ -26,6 +26,7 @@ import java.util.function.Supplier;
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
|
|
|
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
|
|
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
|
|
import org.springframework.boot.context.annotation.Configurations;
|
|
|
|
import org.springframework.boot.context.annotation.Configurations;
|
|
|
@ -199,6 +200,17 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
|
|
|
return newInstance(this.runnerConfiguration.withAllowBeanDefinitionOverriding(allowBeanDefinitionOverriding));
|
|
|
|
return newInstance(this.runnerConfiguration.withAllowBeanDefinitionOverriding(allowBeanDefinitionOverriding));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Specify if circular references between beans should be allowed.
|
|
|
|
|
|
|
|
* @param allowCircularReferences if circular references between beans are allowed
|
|
|
|
|
|
|
|
* @return a new instance with the updated circular references policy
|
|
|
|
|
|
|
|
* @since 2.6.0
|
|
|
|
|
|
|
|
* @see AbstractAutowireCapableBeanFactory#setAllowCircularReferences(boolean)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public SELF withAllowCircularReferences(boolean allowCircularReferences) {
|
|
|
|
|
|
|
|
return newInstance(this.runnerConfiguration.withAllowCircularReferences(allowCircularReferences));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Add an {@link ApplicationContextInitializer} to be called when the context is
|
|
|
|
* Add an {@link ApplicationContextInitializer} to be called when the context is
|
|
|
|
* created.
|
|
|
|
* created.
|
|
|
@ -427,9 +439,13 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
|
|
|
private C createAndLoadContext() {
|
|
|
|
private C createAndLoadContext() {
|
|
|
|
C context = this.runnerConfiguration.contextFactory.get();
|
|
|
|
C context = this.runnerConfiguration.contextFactory.get();
|
|
|
|
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
|
|
|
|
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
|
|
|
|
if (beanFactory instanceof DefaultListableBeanFactory) {
|
|
|
|
if (beanFactory instanceof AbstractAutowireCapableBeanFactory) {
|
|
|
|
((DefaultListableBeanFactory) beanFactory)
|
|
|
|
((AbstractAutowireCapableBeanFactory) beanFactory)
|
|
|
|
.setAllowBeanDefinitionOverriding(this.runnerConfiguration.allowBeanDefinitionOverriding);
|
|
|
|
.setAllowCircularReferences(this.runnerConfiguration.allowCircularReferences);
|
|
|
|
|
|
|
|
if (beanFactory instanceof DefaultListableBeanFactory) {
|
|
|
|
|
|
|
|
((DefaultListableBeanFactory) beanFactory)
|
|
|
|
|
|
|
|
.setAllowBeanDefinitionOverriding(this.runnerConfiguration.allowBeanDefinitionOverriding);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
configureContext(context);
|
|
|
|
configureContext(context);
|
|
|
@ -504,6 +520,8 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
|
|
|
|
|
|
|
|
|
|
|
private boolean allowBeanDefinitionOverriding = false;
|
|
|
|
private boolean allowBeanDefinitionOverriding = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean allowCircularReferences = false;
|
|
|
|
|
|
|
|
|
|
|
|
private List<ApplicationContextInitializer<? super C>> initializers = Collections.emptyList();
|
|
|
|
private List<ApplicationContextInitializer<? super C>> initializers = Collections.emptyList();
|
|
|
|
|
|
|
|
|
|
|
|
private TestPropertyValues environmentProperties = TestPropertyValues.empty();
|
|
|
|
private TestPropertyValues environmentProperties = TestPropertyValues.empty();
|
|
|
@ -525,6 +543,7 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
|
|
|
private RunnerConfiguration(RunnerConfiguration<C> source) {
|
|
|
|
private RunnerConfiguration(RunnerConfiguration<C> source) {
|
|
|
|
this.contextFactory = source.contextFactory;
|
|
|
|
this.contextFactory = source.contextFactory;
|
|
|
|
this.allowBeanDefinitionOverriding = source.allowBeanDefinitionOverriding;
|
|
|
|
this.allowBeanDefinitionOverriding = source.allowBeanDefinitionOverriding;
|
|
|
|
|
|
|
|
this.allowCircularReferences = source.allowCircularReferences;
|
|
|
|
this.initializers = source.initializers;
|
|
|
|
this.initializers = source.initializers;
|
|
|
|
this.environmentProperties = source.environmentProperties;
|
|
|
|
this.environmentProperties = source.environmentProperties;
|
|
|
|
this.systemProperties = source.systemProperties;
|
|
|
|
this.systemProperties = source.systemProperties;
|
|
|
@ -540,6 +559,12 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
|
|
|
return config;
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RunnerConfiguration<C> withAllowCircularReferences(boolean allowCircularReferences) {
|
|
|
|
|
|
|
|
RunnerConfiguration<C> config = new RunnerConfiguration<>(this);
|
|
|
|
|
|
|
|
config.allowCircularReferences = allowCircularReferences;
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RunnerConfiguration<C> withInitializer(ApplicationContextInitializer<? super C> initializer) {
|
|
|
|
private RunnerConfiguration<C> withInitializer(ApplicationContextInitializer<? super C> initializer) {
|
|
|
|
Assert.notNull(initializer, "Initializer must not be null");
|
|
|
|
Assert.notNull(initializer, "Initializer must not be null");
|
|
|
|
RunnerConfiguration<C> config = new RunnerConfiguration<>(this);
|
|
|
|
RunnerConfiguration<C> config = new RunnerConfiguration<>(this);
|
|
|
|