From 7a2110d8a55831dae6bfd0a7f705b60f3b7fd53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 30 Sep 2022 12:25:35 +0200 Subject: [PATCH] Refine Kotlin bean DSL for AOT use case Before this commit, beans registered with the Kotlin bean DSL typically added via SpringApplication#addInitializers were registered 2 times: by the code generated AOT and by the listener executed at runtime. After this commit, such beans are only registered 1 time when AOT generation is involved, and does not require specific reflection hints on native execution anymore. Closes gh-29211 --- .../org/springframework/context/support/BeanDefinitionDsl.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt b/spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt index a137231589..0a60277b5a 100644 --- a/spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt +++ b/spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt @@ -16,6 +16,7 @@ package org.springframework.context.support +import org.springframework.aot.AotDetector import org.springframework.beans.factory.ObjectProvider import org.springframework.beans.factory.config.BeanDefinition import org.springframework.beans.factory.config.BeanDefinitionCustomizer @@ -1145,6 +1146,9 @@ open class BeanDefinitionDsl internal constructor (private val init: BeanDefinit * @param context The `ApplicationContext` to use for registering the beans */ override fun initialize(context: GenericApplicationContext) { + if (AotDetector.useGeneratedArtifacts()) { + return + } this.context = context init() for (child in children) {