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
This commit is contained in:
Sébastien Deleuze
2022-09-30 12:25:35 +02:00
parent d98e27cf79
commit 7a2110d8a5

View File

@@ -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) {