Skip to content

Commit 77ae58e

Browse files
author
Zhiyang.Wang1
committed
Remove deprecated support for FailureAnalyzer setter injection
* Remove deprecated support for `FailureAnalyzer` setter injection at `FailureAnalyzersTests` * remove unused `FailureAnalyzer` at `spring.factories` * fix `application.adoc` Closes spring-projects#38238
1 parent 690cfa2 commit 77ae58e

File tree

3 files changed

+3
-48
lines changed

3 files changed

+3
-48
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition
2525
org.springframework.boot.diagnostics.FailureAnalyzer=\
2626
org.springframework.boot.autoconfigure.data.redis.RedisUrlSyntaxFailureAnalyzer,\
2727
org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\
28-
org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingFailureAnalyzer,\
2928
org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
3029
org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
3130
org.springframework.boot.autoconfigure.jooq.NoDslContextBeanFailureAnalyzer,\

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/application.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following example registers `ProjectConstraintViolationFailureAnalyzer`:
2323
com.example.ProjectConstraintViolationFailureAnalyzer
2424
----
2525

26-
NOTE: If you need access to the `BeanFactory` or the `Environment`, your `FailureAnalyzer` can implement `BeanFactoryAware` or `EnvironmentAware` respectively.
26+
NOTE: If you need access to the `BeanFactory` or the `Environment`, your `FailureAnalyzer` can accept a `BeanFactoryAware` and/or `Environment` as constructor parameters.
2727

2828

2929

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java

+2-46
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
import org.junit.jupiter.api.extension.ExtendWith;
2222

2323
import org.springframework.beans.factory.BeanFactory;
24-
import org.springframework.beans.factory.BeanFactoryAware;
2524
import org.springframework.boot.testsupport.system.CapturedOutput;
2625
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
27-
import org.springframework.context.EnvironmentAware;
2826
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2927
import org.springframework.core.env.Environment;
3028
import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
3129

3230
import static org.assertj.core.api.Assertions.assertThat;
33-
import static org.mockito.ArgumentMatchers.same;
3431
import static org.mockito.BDDMockito.then;
3532
import static org.mockito.Mockito.mock;
3633
import static org.mockito.Mockito.times;
@@ -45,20 +42,13 @@
4542
@ExtendWith(OutputCaptureExtension.class)
4643
class FailureAnalyzersTests {
4744

48-
private static AwareFailureAnalyzer failureAnalyzer;
45+
private static FailureAnalyzer failureAnalyzer;
4946

5047
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
5148

5249
@BeforeEach
5350
void configureMock() {
54-
failureAnalyzer = mock(AwareFailureAnalyzer.class);
55-
}
56-
57-
@Test
58-
void analyzersAreLoadedAndCalled() {
59-
RuntimeException failure = new RuntimeException();
60-
analyzeAndReport(failure, BasicFailureAnalyzer.class, StandardAwareFailureAnalyzer.class);
61-
then(failureAnalyzer).should(times(2)).analyze(failure);
51+
failureAnalyzer = mock(FailureAnalyzer.class);
6252
}
6353

6454
@Test
@@ -77,22 +67,6 @@ void analyzerIsConstructedWithEnvironment(CapturedOutput output) {
7767
assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware");
7868
}
7969

80-
@Test
81-
void beanFactoryIsInjectedIntoBeanFactoryAwareFailureAnalyzers(CapturedOutput output) {
82-
RuntimeException failure = new RuntimeException();
83-
analyzeAndReport(failure, BasicFailureAnalyzer.class, StandardAwareFailureAnalyzer.class);
84-
then(failureAnalyzer).should().setBeanFactory(same(this.context.getBeanFactory()));
85-
assertThat(output).contains("FailureAnalyzers [" + StandardAwareFailureAnalyzer.class.getName()
86-
+ "] implement BeanFactoryAware or EnvironmentAware.");
87-
}
88-
89-
@Test
90-
void environmentIsInjectedIntoEnvironmentAwareFailureAnalyzers() {
91-
RuntimeException failure = new RuntimeException();
92-
analyzeAndReport(failure, BasicFailureAnalyzer.class, StandardAwareFailureAnalyzer.class);
93-
then(failureAnalyzer).should().setEnvironment(same(this.context.getEnvironment()));
94-
}
95-
9670
@Test
9771
void analyzerThatFailsDuringInitializationDoesNotPreventOtherAnalyzersFromBeingCalled() {
9872
RuntimeException failure = new RuntimeException();
@@ -170,22 +144,4 @@ static class EnvironmentConstructorFailureAnalyzer extends BasicFailureAnalyzer
170144

171145
}
172146

173-
interface AwareFailureAnalyzer extends BeanFactoryAware, EnvironmentAware, FailureAnalyzer {
174-
175-
}
176-
177-
static class StandardAwareFailureAnalyzer extends BasicFailureAnalyzer implements AwareFailureAnalyzer {
178-
179-
@Override
180-
public void setEnvironment(Environment environment) {
181-
failureAnalyzer.setEnvironment(environment);
182-
}
183-
184-
@Override
185-
public void setBeanFactory(BeanFactory beanFactory) {
186-
failureAnalyzer.setBeanFactory(beanFactory);
187-
}
188-
189-
}
190-
191147
}

0 commit comments

Comments
 (0)