Description
Christopher Smith opened SPR-12233 and commented
I have a bean that's doing conditional autoconfiguration based on whether a certain property is available in the environment; the actual condition matcher is
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().containsProperty(POSTBACK_URL_PROPERTY);
}
The configuration class then creates a bean using an @Value
injection if that property is present.
Spring 4.0.7->4.1.0 introduced a regression wherein the @Value
is being evaluated even when the @Condition
should not match, causing the context startup to crash. I have debugged, and Spring is in fact running the condition's matcher before proceeding to try (and fail) to extract the property from the environment. I attempted to step through it, but I could not tell whether the environment is erroneously returning true from containsProperty
or the DI container is failing to disable the class when it has a false condition.
A simple Spring Boot application demonstrating the behavior is available at the GitHub link. Change the Spring version in the POM to 4.1.0 to demonstrate the bug; the launcher will crash on startup.
Affects: 4.1 GA
Reference URL: https://github.com/chrylis/spring-SPR-12233
Issue Links:
- Spring may invoke @Bean methods too early in case of a circular reference [SPR-12018] #16634 Spring may invoke
@Bean
methods too early in case of a circular reference - @Configuration imported via @ImportResource is not processed [SPR-11723] #16345
@Configuration
imported via@ImportResource
is not processed
Referenced from: commits 4c59d85