diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java index ef174a22af..728a0c91e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java @@ -26,9 +26,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; @@ -57,18 +55,17 @@ import org.springframework.util.ClassUtils; * * @author Stephane Nicoll * @author Phillip Webb + * @author Scott Frederick */ -class NoSuchBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer - implements BeanFactoryAware { +class NoSuchBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer { - 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()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java index 7dfa8484ba..8c241c7178 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java @@ -46,10 +46,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() { @@ -208,11 +212,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) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java index df040bfb86..d493c47894 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java @@ -90,9 +90,9 @@ final class FailureAnalyzers implements SpringBootExceptionReporter { String awareAnalyzerNames = StringUtils.collectionToCommaDelimitedString(awareAnalyzers.stream() .map((analyzer) -> analyzer.getClass().getName()).collect(Collectors.toList())); logger.warn(LogMessage.format( - "FailureAnalyzers [%s] implement BeanFactoryAware or EnvironmentAware." + "FailureAnalyzers [%s] implement BeanFactoryAware or EnvironmentAware. " + "Support for these interfaces on FailureAnalyzers is deprecated, " - + "and will be removed in a future release." + + "and will be removed in a future release. " + "Instead provide a constructor that accepts BeanFactory or Environment parameters.", awareAnalyzerNames)); if (context == null) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java index aa97860230..44de27d6cb 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzer.java @@ -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 - implements BeanFactoryAware { +class BeanCurrentlyInCreationFailureAnalyzer extends AbstractFailureAnalyzer { - 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 diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java index e9ab9ab6cd..7f1cff0090 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java @@ -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 implements EnvironmentAware { + extends AbstractFailureAnalyzer { - private ConfigurableEnvironment environment; + private final ConfigurableEnvironment environment; - @Override - public void setEnvironment(Environment environment) { + InvalidConfigurationPropertyValueFailureAnalyzer(Environment environment) { this.environment = (ConfigurableEnvironment) environment; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzer.java index 429aa21f5f..cc1b638cf3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzer.java @@ -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 implements EnvironmentAware { + extends AbstractFailureAnalyzer { - private ConfigurableEnvironment environment; + private final ConfigurableEnvironment environment; - @Override - public void setEnvironment(Environment environment) { + MutuallyExclusiveConfigurationPropertiesFailureAnalyzer(Environment environment) { this.environment = (ConfigurableEnvironment) environment; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzer.java index aa2e540954..555df79bce 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzer.java @@ -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 - implements BeanFactoryAware { +class NoUniqueBeanDefinitionFailureAnalyzer extends AbstractInjectionFailureAnalyzer { - 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; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java index 3324acb571..ba6f4f6e5c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java @@ -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; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzerTests.java index 45d47f6e5a..f8cf1a3e2b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzerTests.java @@ -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); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests.java index 04e373a18c..a81645e36f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests.java @@ -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); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzerTests.java index aebbab4bbb..b14fcaa76d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionFailureAnalyzerTests.java @@ -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) {