Use side-effect free environment with tests rather than converting

Refine the logic introduced in 64270eca to use a side-effect free
Environment implementation rather than converting the Environment early.

Early conversion can cause condition evaluation issues if
`src/test/resources/application.properties` files are bound to the
`SpringApplication`. Specifically the `spring.main.web-application-type`
property can change the `Environment` type which must happen before
conditions are evaluated.

Fixes gh-29169
This commit is contained in:
Phillip Webb
2022-01-11 19:08:54 -08:00
parent 9cf55808fb
commit eb6b48fff0
7 changed files with 93 additions and 26 deletions

View File

@@ -389,7 +389,9 @@ public class SpringApplication {
* @param environment the environment to convert
* @return the converted environment
* @since 2.5.7
* @deprecated since 2.5.8 for removal in 2.7.0
*/
@Deprecated
public StandardEnvironment convertEnvironment(ConfigurableEnvironment environment) {
return new EnvironmentConverter(getClassLoader()).convertEnvironmentIfNecessary(environment,
deduceEnvironmentClass());