Skip to content

Commit 9b8c45c

Browse files
committed
Polish "Remove deprecated support for FailureAnalyzer setter injection"
See gh-38322
1 parent 697b252 commit 9b8c45c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,7 +58,12 @@ public FailureAnalyzers(ConfigurableApplicationContext context) {
5858

5959
FailureAnalyzers(ConfigurableApplicationContext context, SpringFactoriesLoader springFactoriesLoader) {
6060
this.springFactoriesLoader = springFactoriesLoader;
61-
this.analyzers = springFactoriesLoader.load(FailureAnalyzer.class, getArgumentResolver(context),
61+
this.analyzers = loadFailureAnalyzers(context, this.springFactoriesLoader);
62+
}
63+
64+
private static List<FailureAnalyzer> loadFailureAnalyzers(ConfigurableApplicationContext context,
65+
SpringFactoriesLoader springFactoriesLoader) {
66+
return springFactoriesLoader.load(FailureAnalyzer.class, getArgumentResolver(context),
6267
FailureHandler.logging(logger));
6368
}
6469

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import org.junit.jupiter.api.extension.ExtendWith;
2222

2323
import org.springframework.beans.factory.BeanFactory;
24-
import org.springframework.boot.testsupport.system.CapturedOutput;
2524
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
2625
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2726
import org.springframework.core.env.Environment;
@@ -52,19 +51,24 @@ void configureMock() {
5251
}
5352

5453
@Test
55-
void analyzerIsConstructedWithBeanFactory(CapturedOutput output) {
54+
void analyzersAreLoadedAndCalled() {
55+
RuntimeException failure = new RuntimeException();
56+
analyzeAndReport(failure, BasicFailureAnalyzer.class, BasicFailureAnalyzer.class);
57+
then(failureAnalyzer).should(times(2)).analyze(failure);
58+
}
59+
60+
@Test
61+
void analyzerIsConstructedWithBeanFactory() {
5662
RuntimeException failure = new RuntimeException();
5763
analyzeAndReport(failure, BasicFailureAnalyzer.class, BeanFactoryConstructorFailureAnalyzer.class);
5864
then(failureAnalyzer).should(times(2)).analyze(failure);
59-
assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware");
6065
}
6166

6267
@Test
63-
void analyzerIsConstructedWithEnvironment(CapturedOutput output) {
68+
void analyzerIsConstructedWithEnvironment() {
6469
RuntimeException failure = new RuntimeException();
6570
analyzeAndReport(failure, BasicFailureAnalyzer.class, EnvironmentConstructorFailureAnalyzer.class);
6671
then(failureAnalyzer).should(times(2)).analyze(failure);
67-
assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware");
6872
}
6973

7074
@Test

0 commit comments

Comments
 (0)