Skip to content
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

Closed
snicoll opened this issue Jul 19, 2024 · 3 comments
Closed

Add option to ignore bean registration with AOT #33243

snicoll opened this issue Jul 19, 2024 · 3 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Jul 19, 2024

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.

@snicoll snicoll added type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Jul 19, 2024
@snicoll snicoll added this to the 6.2.0-M7 milestone Jul 19, 2024
@snicoll snicoll self-assigned this Jul 19, 2024
snicoll added a commit to snicoll/spring-framework that referenced this issue Jul 21, 2024
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
@snicoll
Copy link
Member Author

snicoll commented Jul 21, 2024

This wasn't really hard to implement and it shed some light on BeanRegistrationExcludeFilter that could just as well prepare the context by setting the attribute now we're fairly confident that attributes aren't persisted in AOT-processed bean definitions.

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.

@snicoll snicoll added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Jul 21, 2024
@snicoll
Copy link
Member Author

snicoll commented Jul 21, 2024

When merging this, another look at spring-projects/spring-boot#34563 to remove the filter should be helpful.

@snicoll
Copy link
Member Author

snicoll commented Jul 24, 2024

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.

@snicoll snicoll removed the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant