-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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?
spring-framework/spring-core/src/main/java/org/springframework/aot/AotDetector.java
Lines 22 to 29 in c1014f5
/** * Utility for determining if AOT-processed optimizations must be used rather * than the regular runtime. Strictly for internal use within the framework. * * @author Stephane Nicoll * @since 6.0 */ public abstract class AotDetector { - 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