spring-projects / spring-projects/spring-framework

Reject conditional `@EnableScheduling` / `@EnableCaching` declarations that rely on the `REGISTER_BEAN` phase

Open
#35,001 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Minimal example reproducing the problem: https://github.com/klach-ocado/enablescheduling-configurationphase-issue

  • AaaUnrelatedAutoConfiguration is where @EnableScheduling annotation was added, or (another case, when @EnableScheduling was already there) where existing conditions were collapsed to a single @Conditional.
  • TriggeringAutoConfiguration (before = TriggeredAutoConfiguration.class) registers TriggeringBean.
  • TriggeredAutoConfiguration depends on TriggeringBean being 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:


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: https://github.com/spring-projects/spring-framework/issues/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal reproducer linked in the issue and compare the behavior with and without the @EnableScheduling declaration in AaaUnrelatedAutoConfiguration. Then trace how @EnableScheduling and @EnableCaching interact with REGISTER_BEAN conditions, and define a validation or warning whose completion is demonstrated by preventing or clearly reporting the reproduced skipped auto-configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.