spring-projects / spring-projects/spring-framework

AOT registers BeanDefinitionRegistryPostProcessor beans causing duplication of configuration

Open
#30,411 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core theme: aot type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

AOT retains registrations of BeanDefinitionRegistryPostProcessor beans, causing them to run again under AOT. Other than meaning you don't realise the benefits of avoidance of post-processing, if those processors register definitions unconditionally they fail with:

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'GrpcClient_myclient' could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

Appears that Boot is handling this conditionally in several places with AotDetector, but that appears to be explicitly for internal use.

In this specific case, it feels like AOT should filter the registrations, but what's the recommendation for similar patterns in end-user implementations?

Example project:

https://github.com/DanielThomas/spring-aot-issues/tree/dannyt/post-processor-duplicate

Run and note the failure:

./gradlew bootJar && java -Dspring.aot.enabled=true -jar build/libs/demo-0.0.1-SNAPSHOT.jar

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 with spring-core/src/main/java/org/springframework/aot/AotDetector.java and compare the referenced Boot uses of AotDetector.useGeneratedArtifacts. Reproduce the failure with the linked example project using ./gradlew bootJar && java -Dspring.aot.enabled=true -jar build/libs/demo-0.0.1-SNAPSHOT.jar. Done means the post-processor registrations do not cause duplicate bean-definition failures under AOT.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.