-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin functional config DSL should prevent beans to be registered twice in AOT-optimized contexts #29211
Comments
Thanks for the report, as far as I can see this has nothing to do with kotlin or the functional config. When AOT processes the context, it honors the initializers that you've defined. This defines a bean in the bean factory so it's processed. When the AOT-optimized context runs, it uses the generated context that registers a bean, and then call your initializer again. Can you please confirm that my analysis is correct (you should see some generated code for |
I had a look and I think your analysis is correct @snicoll. There is some code generated (
|
ApplicationListener<T>
s added via functional config in Kotlin get run twice in an AOT native image context
Thanks for testing @sdeleuze. We've been discussing this one as part of spring-projects/spring-boot#32262 and we believe that this should work out-of-the-box. Our thinking is that adding the WDYT? |
Yeah it was not a Gradle project (so painful to test by modifying Spring Framework snapshots) so I went the easy way to do a basic test. I am ok with your proposal, but the fix will be Kotlin DSL specific and people using directly the Java functional API to do the same thing will continue to see the double registration if they don't do the |
Yes. Our plan is to gather more feedback and then make an API change if necessary with more feedback. This one looks like it can be handled internally so we should do that regardless. |
here's the spring initializr configuration i used
here's some kotlin code
I compile it using
mvn -Pnative -DskipTests clean package
to get a GraalVM binary. if I leave the code as-is, on the JRE, I seeJames
andJosh
. If I run it as a native image on GraalVM, I seeJames
,Josh
,James
,Josh
. (the same thing, twice). My listener is being called twice, for some reason.Odder still, if I use
@Bean
to register theMyListener
or if I use@Component
, then in those cases I only seeJosh
, andJames
once. Not twice.The text was updated successfully, but these errors were encountered: