Skip to content

Commit 7a2110d

Browse files
committed
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
1 parent d98e27c commit 7a2110d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.context.support
1818

19+
import org.springframework.aot.AotDetector
1920
import org.springframework.beans.factory.ObjectProvider
2021
import org.springframework.beans.factory.config.BeanDefinition
2122
import org.springframework.beans.factory.config.BeanDefinitionCustomizer
@@ -1145,6 +1146,9 @@ open class BeanDefinitionDsl internal constructor (private val init: BeanDefinit
11451146
* @param context The `ApplicationContext` to use for registering the beans
11461147
*/
11471148
override fun initialize(context: GenericApplicationContext) {
1149+
if (AotDetector.useGeneratedArtifacts()) {
1150+
return
1151+
}
11481152
this.context = context
11491153
init()
11501154
for (child in children) {

0 commit comments

Comments
 (0)