Spring Boot version:2.1.4

There are two steps in the method run of SpringApplication.class

ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments);
...
...
exceptionReporters = this.getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[]{ConfigurableApplicationContext.class}, context);

In step 1, we analysis our config file into environment, it has been handled with some steps.

In step 2, we find all FailureAnalyzer,and call prepareAnalyzer on each of them

private void prepareAnalyzer(ConfigurableApplicationContext context, FailureAnalyzer analyzer) {
    ...
    ...
    if (analyzer instanceof EnvironmentAware) {
        ((EnvironmentAware)analyzer).setEnvironment(context.getEnvironment());
    }
}

The environment we set into those analyzers is not the same as the one we handled. It is a new one during the initialization process of ConfigurableApplicationContext , which will be replaced by the environment created in step1.

So when the program starts abnormally,FailureAnalyzer may work with a wrong environment.

Is there anything wrong with my understanding ? Thank you.

Comment From: wilkinsona

Open source support for 2.1.x ended in October 2019. Please upgrade to Spring Boot 2.6.x or 2.7.x. If you believe that a similar problem exists there, please share a minimal sample that reproduces it. We can then re-open this issue and take another look.

Comment From: yiyuankafei

Thanks for your answer.

I checked this part in Spring Boot version 2.7.2

Set environment into FailureAnalyzer occured after exception thrown , but it also get the environment from ConfigurableApplicationContext

If exception occured before set our handled environment into ConfigurableApplicationContext in method prepareContext, it will also lead to this problem.

Comment From: snicoll

@yiyuankafei as Andy requested, please share a minimal sample that reproduces the problem you've described. You can do so by attaching a zip to this issue or pushing it to a separate GitHub repository and sharing the link.

Comment From: yiyuankafei

I took another look in version 2.7.2 and found that the situation I thought will not appear in fact, thanks a lot~