spring-projects / spring-projects/spring-framework
AOT registers BeanDefinitionRegistryPostProcessor beans causing duplication of configuration
Nobody has claimed this yet.
- 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?
- https://github.com/spring-projects/spring-framework/blob/c1014f598916832a293ef40acc5a99765c242953/spring-core/src/main/java/org/springframework/aot/AotDetector.java#L22-L29
- https://github.com/spring-projects/spring-boot/blob/2c0edfd0b5046ecf4ecaaba628e63aea323922ac/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializer.java#L65-L67
- https://github.com/search?q=repo%3Aspring-projects%2Fspring-boot+AotDetector.useGeneratedArtifacts&type=code
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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