-
Couldn't load subscription status.
- Fork 38.8k
Description
Minimal example reproducing the problem: https://github.com/klach-ocado/enablescheduling-configurationphase-issue
AaaUnrelatedAutoConfigurationis where@EnableSchedulingannotation was added, or (another case, when@EnableSchedulingwas already there) where existing conditions were collapsed to a single@Conditional.TriggeringAutoConfiguration(before = TriggeredAutoConfiguration.class) registersTriggeringBean.TriggeredAutoConfigurationdepends onTriggeringBeanbeing registered, and has@EnableScheduling.
Normally those classes are in separate modules, TriggeringAutoConfiguration is in a module that is an extension to the module with TriggeredAutoConfiguration, no other relations.
What is known already?
There is an issue that @EnableScheduling annotation added to a seemingly unrelated class (AaaUnrelatedAutoConfiguration),
or collapsing existing conditions in an unrelated class to a single @Conditional
causes existing (and working previously) @AutoConfiguration-s with @Conditional with ConfigurationPhase.REGISTER_BEAN
(e.g. @ConditionalOnBean) being skipped.
AaaUnrelatedAutoConfiguration class has comments for possible changes in the code showing that it's indeed that class that caused problems.
There of course are other options, like in TriggeredAutoConfiguration moving @ConditionalOnBean from the class to the @Bean method
but let's assume we don't want @EnableScheduling being activated unnecessarily.
Similar issues:
- AutoConfiguration is skipped because of @EnableScheduling spring-boot#14018
- TrackedConditionEvaluator skips loading bean definitions for configuration classes that should not be skipped [SPR-17153] #21690
What enhancement is suggested?
Rather than introducing changes to the condition handling for configuration classes, or to the logic of @Import annotation (used underneath of @EnableScheduling),
maybe it could be possible to add some validation for @EnableScheduling annotation?
Among common @Enable* annotations, also @EnableCaching may be worth to protect, other ones are less likely to be used with REGISTER_BEAN phase.
I consider a protection similar to this one: #23206
(does not have to be so sophisticated),
or at least some warning in logs (but typically only org.springframework.boot.autoconfigure logger is enabled by users, which may not cover that).
Rationale: Those are common annotations, and user does not expect that e.g. collapsing existing conditions to a single @Conditional
in one class can accidentally cause skipping completely unrelated @AutoConfiguration-s.