Migrate FailureAnalyzers to constructor injection
All `FailureAnalyzer` implementations should use constructor injection for `BeanFactory` and `Environment` instead of implementing `BeanFactoryAware` or `EnvironmentAware` interfaces. Fixes gh-30585
This commit is contained in:
parent
612e4114d2
commit
d67dcf16cd
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -27,9 +27,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.InjectionPoint;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
|
@ -63,18 +61,17 @@ import org.springframework.util.ClassUtils;
|
|||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class NoSuchBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer<NoSuchBeanDefinitionException>
|
||||
implements BeanFactoryAware {
|
||||
class NoSuchBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer<NoSuchBeanDefinitionException> {
|
||||
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
private final ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
private MetadataReaderFactory metadataReaderFactory;
|
||||
private final MetadataReaderFactory metadataReaderFactory;
|
||||
|
||||
private ConditionEvaluationReport report;
|
||||
private final ConditionEvaluationReport report;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
NoSuchBeanDefinitionFailureAnalyzer(BeanFactory beanFactory) {
|
||||
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory);
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
||||
this.metadataReaderFactory = new CachingMetadataReaderFactory(this.beanFactory.getBeanClassLoader());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -49,10 +49,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link NoSuchBeanDefinitionFailureAnalyzer}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class NoSuchBeanDefinitionFailureAnalyzerTests {
|
||||
|
||||
private final NoSuchBeanDefinitionFailureAnalyzer analyzer = new NoSuchBeanDefinitionFailureAnalyzer();
|
||||
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
private final NoSuchBeanDefinitionFailureAnalyzer analyzer = new NoSuchBeanDefinitionFailureAnalyzer(
|
||||
this.context.getBeanFactory());
|
||||
|
||||
@Test
|
||||
void failureAnalysisForMultipleBeans() {
|
||||
|
@ -227,11 +231,10 @@ class NoSuchBeanDefinitionFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
private FatalBeanException createFailure(Class<?> config, String... environment) {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
this.analyzer.setBeanFactory(context.getBeanFactory());
|
||||
TestPropertyValues.of(environment).applyTo(context);
|
||||
context.register(config);
|
||||
context.refresh();
|
||||
try {
|
||||
TestPropertyValues.of(environment).applyTo(this.context);
|
||||
this.context.register(config);
|
||||
this.context.refresh();
|
||||
return null;
|
||||
}
|
||||
catch (FatalBeanException ex) {
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.diagnostics.analyzer
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
|
@ -18,11 +34,12 @@ import org.springframework.context.annotation.Configuration
|
|||
* on the classpath.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@ClassPathExclusions("kotlin-reflect*.jar")
|
||||
class KotlinNoSuchBeanFailureAnalyzerNoKotlinReflectTests {
|
||||
|
||||
private val analyzer = NoSuchBeanDefinitionFailureAnalyzer()
|
||||
private val context = AnnotationConfigApplicationContext()
|
||||
|
||||
@Test
|
||||
fun failureAnalysisForConfigurationPropertiesThatMaybeShouldHaveBeenConstructorBound() {
|
||||
|
@ -37,7 +54,6 @@ class KotlinNoSuchBeanFailureAnalyzerNoKotlinReflectTests {
|
|||
private fun createFailure(config: Class<*>, vararg environment: String): FatalBeanException? {
|
||||
try {
|
||||
AnnotationConfigApplicationContext().use { context ->
|
||||
this.analyzer.setBeanFactory(context.beanFactory)
|
||||
TestPropertyValues.of(*environment).applyTo(context)
|
||||
context.register(config)
|
||||
context.refresh()
|
||||
|
@ -50,7 +66,8 @@ class KotlinNoSuchBeanFailureAnalyzerNoKotlinReflectTests {
|
|||
}
|
||||
|
||||
private fun analyzeFailure(failure: Exception?): FailureAnalysis? {
|
||||
val analysis = this.analyzer.analyze(failure)
|
||||
val analyzer = NoSuchBeanDefinitionFailureAnalyzer(this.context.beanFactory)
|
||||
val analysis = analyzer.analyze(failure)
|
||||
if (analysis != null) {
|
||||
LoggingFailureAnalysisReporter().report(analysis)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,11 +19,9 @@ package org.springframework.boot.diagnostics.analyzer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.InjectionPoint;
|
||||
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
||||
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
|
||||
|
@ -36,17 +34,19 @@ import org.springframework.util.StringUtils;
|
|||
* {@link BeanCurrentlyInCreationException}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<BeanCurrentlyInCreationException>
|
||||
implements BeanFactoryAware {
|
||||
class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer<BeanCurrentlyInCreationException> {
|
||||
|
||||
private AbstractAutowireCapableBeanFactory beanFactory;
|
||||
private final AbstractAutowireCapableBeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
if (beanFactory instanceof AbstractAutowireCapableBeanFactory) {
|
||||
BeanCurrentlyInCreationFailureAnalyzer(BeanFactory beanFactory) {
|
||||
if (beanFactory != null && beanFactory instanceof AbstractAutowireCapableBeanFactory) {
|
||||
this.beanFactory = (AbstractAutowireCapableBeanFactory) beanFactory;
|
||||
}
|
||||
else {
|
||||
this.beanFactory = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -27,7 +27,6 @@ import org.springframework.boot.diagnostics.FailureAnalysis;
|
|||
import org.springframework.boot.diagnostics.FailureAnalyzer;
|
||||
import org.springframework.boot.origin.Origin;
|
||||
import org.springframework.boot.origin.OriginLookup;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
@ -38,14 +37,14 @@ import org.springframework.util.StringUtils;
|
|||
* {@link InvalidConfigurationPropertyValueException}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class InvalidConfigurationPropertyValueFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<InvalidConfigurationPropertyValueException> implements EnvironmentAware {
|
||||
extends AbstractFailureAnalyzer<InvalidConfigurationPropertyValueException> {
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
private final ConfigurableEnvironment environment;
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
InvalidConfigurationPropertyValueFailureAnalyzer(Environment environment) {
|
||||
this.environment = (ConfigurableEnvironment) environment;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -32,7 +32,6 @@ import org.springframework.boot.diagnostics.FailureAnalysis;
|
|||
import org.springframework.boot.diagnostics.FailureAnalyzer;
|
||||
import org.springframework.boot.origin.Origin;
|
||||
import org.springframework.boot.origin.OriginLookup;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
@ -42,14 +41,14 @@ import org.springframework.core.env.PropertySource;
|
|||
* {@link MutuallyExclusiveConfigurationPropertiesException}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class MutuallyExclusiveConfigurationPropertiesFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<MutuallyExclusiveConfigurationPropertiesException> implements EnvironmentAware {
|
||||
extends AbstractFailureAnalyzer<MutuallyExclusiveConfigurationPropertiesException> {
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
private final ConfigurableEnvironment environment;
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
MutuallyExclusiveConfigurationPropertiesFailureAnalyzer(Environment environment) {
|
||||
this.environment = (ConfigurableEnvironment) environment;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,9 +16,7 @@
|
|||
|
||||
package org.springframework.boot.diagnostics.analyzer;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -32,14 +30,13 @@ import org.springframework.util.StringUtils;
|
|||
* by a {@link NoUniqueBeanDefinitionException}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class NoUniqueBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer<NoUniqueBeanDefinitionException>
|
||||
implements BeanFactoryAware {
|
||||
class NoUniqueBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer<NoUniqueBeanDefinitionException> {
|
||||
|
||||
private ConfigurableBeanFactory beanFactory;
|
||||
private final ConfigurableBeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
NoUniqueBeanDefinitionFailureAnalyzer(BeanFactory beanFactory) {
|
||||
Assert.isInstanceOf(ConfigurableBeanFactory.class, beanFactory);
|
||||
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -43,10 +43,14 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
* Tests for {@link BeanCurrentlyInCreationFailureAnalyzer}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class BeanCurrentlyInCreationFailureAnalyzerTests {
|
||||
|
||||
private final BeanCurrentlyInCreationFailureAnalyzer analyzer = new BeanCurrentlyInCreationFailureAnalyzer();
|
||||
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
private final BeanCurrentlyInCreationFailureAnalyzer analyzer = new BeanCurrentlyInCreationFailureAnalyzer(
|
||||
this.context.getBeanFactory());
|
||||
|
||||
@Test
|
||||
void cyclicBeanMethods() throws IOException {
|
||||
|
@ -131,13 +135,13 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void cycleWithCircularReferencesAllowed() throws IOException {
|
||||
void cycleWithCircularReferencesAllowed() {
|
||||
FailureAnalysis analysis = performAnalysis(CyclicBeanMethodsConfiguration.class, true);
|
||||
assertThat(analysis.getAction()).contains("Despite circular references being allowed");
|
||||
}
|
||||
|
||||
@Test
|
||||
void cycleWithCircularReferencesProhibited() throws IOException {
|
||||
void cycleWithCircularReferencesProhibited() {
|
||||
FailureAnalysis analysis = performAnalysis(CyclicBeanMethodsConfiguration.class, false);
|
||||
assertThat(analysis.getAction()).contains("As a last resort");
|
||||
}
|
||||
|
@ -159,13 +163,12 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
private Exception createFailure(Class<?> configuration, boolean allowCircularReferences) {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(configuration);
|
||||
AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) context
|
||||
try {
|
||||
this.context.register(configuration);
|
||||
AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) this.context
|
||||
.getBeanFactory();
|
||||
this.analyzer.setBeanFactory(beanFactory);
|
||||
beanFactory.setAllowCircularReferences(allowCircularReferences);
|
||||
context.refresh();
|
||||
this.context.refresh();
|
||||
fail("Expected failure did not occur");
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link InvalidConfigurationPropertyValueFailureAnalyzer}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
||||
|
||||
|
@ -43,7 +44,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
void analysisWithNullEnvironment() {
|
||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||
"test.property", "invalid", "This is not valid.");
|
||||
FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer().analyze(failure);
|
||||
FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer(null).analyze(failure);
|
||||
assertThat(analysis).isNull();
|
||||
}
|
||||
|
||||
|
@ -106,8 +107,8 @@ class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
private FailureAnalysis performAnalysis(InvalidConfigurationPropertyValueException failure) {
|
||||
InvalidConfigurationPropertyValueFailureAnalyzer analyzer = new InvalidConfigurationPropertyValueFailureAnalyzer();
|
||||
analyzer.setEnvironment(this.environment);
|
||||
InvalidConfigurationPropertyValueFailureAnalyzer analyzer = new InvalidConfigurationPropertyValueFailureAnalyzer(
|
||||
this.environment);
|
||||
return analyzer.analyze(failure);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -39,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link MutuallyExclusiveConfigurationPropertiesFailureAnalyzer}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests {
|
||||
|
||||
|
@ -49,7 +50,7 @@ class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests {
|
|||
MutuallyExclusiveConfigurationPropertiesException failure = new MutuallyExclusiveConfigurationPropertiesException(
|
||||
new HashSet<>(Arrays.asList("com.example.a", "com.example.b")),
|
||||
new HashSet<>(Arrays.asList("com.example.a", "com.example.b")));
|
||||
FailureAnalysis failureAnalysis = new MutuallyExclusiveConfigurationPropertiesFailureAnalyzer()
|
||||
FailureAnalysis failureAnalysis = new MutuallyExclusiveConfigurationPropertiesFailureAnalyzer(null)
|
||||
.analyze(failure);
|
||||
assertThat(failureAnalysis).isNull();
|
||||
}
|
||||
|
@ -112,8 +113,8 @@ class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
private FailureAnalysis performAnalysis(MutuallyExclusiveConfigurationPropertiesException failure) {
|
||||
MutuallyExclusiveConfigurationPropertiesFailureAnalyzer analyzer = new MutuallyExclusiveConfigurationPropertiesFailureAnalyzer();
|
||||
analyzer.setEnvironment(this.environment);
|
||||
MutuallyExclusiveConfigurationPropertiesFailureAnalyzer analyzer = new MutuallyExclusiveConfigurationPropertiesFailureAnalyzer(
|
||||
this.environment);
|
||||
return analyzer.analyze(failure);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -36,10 +36,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link NoUniqueBeanDefinitionFailureAnalyzer}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class NoUniqueBeanDefinitionFailureAnalyzerTests {
|
||||
|
||||
private final NoUniqueBeanDefinitionFailureAnalyzer analyzer = new NoUniqueBeanDefinitionFailureAnalyzer();
|
||||
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
private final NoUniqueBeanDefinitionFailureAnalyzer analyzer = new NoUniqueBeanDefinitionFailureAnalyzer(
|
||||
this.context.getBeanFactory());
|
||||
|
||||
@Test
|
||||
void failureAnalysisForFieldConsumer() {
|
||||
|
@ -90,18 +94,15 @@ class NoUniqueBeanDefinitionFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
private BeanCreationException createFailure(Class<?> consumer) {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(DuplicateBeansProducer.class, consumer);
|
||||
context.setParent(new AnnotationConfigApplicationContext(ParentProducer.class));
|
||||
try {
|
||||
context.refresh();
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
this.analyzer.setBeanFactory(context.getBeanFactory());
|
||||
return ex;
|
||||
}
|
||||
return null;
|
||||
this.context.register(DuplicateBeansProducer.class, consumer);
|
||||
this.context.setParent(new AnnotationConfigApplicationContext(ParentProducer.class));
|
||||
try {
|
||||
this.context.refresh();
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
return ex;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private FailureAnalysis analyzeFailure(BeanCreationException failure) {
|
||||
|
|
Loading…
Reference in New Issue