@EventListener(ApplicationReadyEvent.class)
@ConditionalOnProperty(havingValue = "true", value = USE_SECOND_LEVEL_CACHE)
public void someEventHandler() {
Conditional is silently ignored and has no effect.
If it doesn't work with @EventListener
, to prevent ambiguous behavior where the code doesn't do what developer hoped it would do, it should throw an erro.
Comment From: wilkinsona
There's no condition evaluation at all on @EventListener
methods as conditions are intended for use on @Configuration
classes and their @Bean
methods to control bean registration. The methods could perhaps be made condition but this would require changes in Spring Framework as it's responsible for @EventListener
support and the general condition evaluation framework.
Throwing an error when @ConditionalOnProperty
is used incorrectly would require the expense of looking up the conditional annotations that's only of benefit when the annotation has been used incorrectly. It would also set a precedent and lead to an expectation that an error is thrown when an annotation is used incorrectly. I think this would be prohibitively expensive so it isn't something that would should do. Thanks anyway for the suggestion.