-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Add option to ignore bean registration with AOT #33243
Comments
This commits allows a particular bean definition to be excluded from AOT processing using an attribute. If BeanRegistrationAotProcessor#IGNORE_REGISTRATION_ATTRIBUTE is set to `true`, then the bean definition is excluded. This complement the existing BeanRegistrationExcludeFilter capability. Closes spring-projectsgh-33243
This wasn't really hard to implement and it shed some light on I've tried to spike a bit how that would be used and the Kotlin DSL does not seem to keep track of what it does. If we update the DSL to set the attribute on the bean definitions that it generates then nothing is being contributed (as everything is skipped) and we no longer call the DSL at runtime. I wonder if someone with a good understanding of the Kotlin DSL could help me understand how we could invoke that code again. |
When merging this, another look at spring-projects/spring-boot#34563 to remove the filter should be helpful. |
I've found out what's going on and have a working sample. The initializer disables itself when it run in AOT mode, see #29211 - The situation describe in that issue was broken as, back then, we were not checking for instance suppliers. |
When an
ApplicationContext
is optimized by Spring AOT, there are a number of limitations. One of them is that the bean registration cannot use an instance supplier as it isn't possible for AOT to generate a bean registration that calls it.#29555 is a concrete example of this problem where the use of the Kotlin DSL makes it so that it fails out of-the-box.
Certain callbacks are execute twice at the moment, once when the context is created ahead-of-time for it to be processed and once more at runtime because the component has been registered. When we have this flexibility, it would be nice to instruct AOT to ignore the bean registration. Adding something like
AOT_PROCESSING_IGNORE_REGISTRATION
on the bean definition could do it.This way the bean definition won't be contributed and won't suffer that limitation. At runtime, the callback that is invoked would create the bean.
The text was updated successfully, but these errors were encountered: