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 cf9bb3f199..a0e1aa7eda 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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. @@ -58,7 +58,12 @@ final class FailureAnalyzers implements SpringBootExceptionReporter { FailureAnalyzers(ConfigurableApplicationContext context, SpringFactoriesLoader springFactoriesLoader) { this.springFactoriesLoader = springFactoriesLoader; - this.analyzers = springFactoriesLoader.load(FailureAnalyzer.class, getArgumentResolver(context), + this.analyzers = loadFailureAnalyzers(context, this.springFactoriesLoader); + } + + private static List loadFailureAnalyzers(ConfigurableApplicationContext context, + SpringFactoriesLoader springFactoriesLoader) { + return springFactoriesLoader.load(FailureAnalyzer.class, getArgumentResolver(context), FailureHandler.logging(logger)); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java index 42637ed597..0ed9267e6e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2024 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. @@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.BeanFactory; -import org.springframework.boot.testsupport.system.CapturedOutput; import org.springframework.boot.testsupport.system.OutputCaptureExtension; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.Environment; @@ -52,19 +51,24 @@ class FailureAnalyzersTests { } @Test - void analyzerIsConstructedWithBeanFactory(CapturedOutput output) { + void analyzersAreLoadedAndCalled() { RuntimeException failure = new RuntimeException(); - analyzeAndReport(failure, BasicFailureAnalyzer.class, BeanFactoryConstructorFailureAnalyzer.class); + analyzeAndReport(failure, BasicFailureAnalyzer.class, BasicFailureAnalyzer.class); then(failureAnalyzer).should(times(2)).analyze(failure); - assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware"); } @Test - void analyzerIsConstructedWithEnvironment(CapturedOutput output) { + void analyzerIsConstructedWithBeanFactory() { + RuntimeException failure = new RuntimeException(); + analyzeAndReport(failure, BasicFailureAnalyzer.class, BeanFactoryConstructorFailureAnalyzer.class); + then(failureAnalyzer).should(times(2)).analyze(failure); + } + + @Test + void analyzerIsConstructedWithEnvironment() { RuntimeException failure = new RuntimeException(); analyzeAndReport(failure, BasicFailureAnalyzer.class, EnvironmentConstructorFailureAnalyzer.class); then(failureAnalyzer).should(times(2)).analyze(failure); - assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware"); } @Test