spring-projects / spring-projects/spring-framework
Introduce a new hook point for Optimizing a Bean if it is present at runtime
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
As Spring AOT should offer a way to run an application without a locked down BeanFactory, we need a way to keep some of those optimizations.
A typical example is Spring Data AOT repositories: the current optimization generate a class and register the optimized class as fragment using a property on the BeanDefinition. This is quite interesting as we'd be able to do this at runtime, too.
Regardless of this ask, there is also a bit of a gap in the current API: when processing a RegisteredBean is is very much tied to bean registration. We don't really have something more isolated. BeanRegistrationCode allows to add an instance post-processor but it only is invoked with full bean registration. The concept of RegisteredBean is also confusing as we can't really use it to process a bean that may or may not be contributed at runtime.
Looking at the Spring Data use case, it could be the following:
- It is invoked with a matching bean that may or may not be present at runtime
- The same code generation API is provided so that the AOT repository fragment can be generated as before
- An instance callback can be provided, but a customizer of the bean definition as well. In that customizer we'd set the property value on the bean definition.
On the Spring AOT side, we would then need to call whatever was generated if such bean was contributor. We could reuse the existing BeanFactoryPostProcessor (tuning the bean definition) or BeanPostProcessor (instance callback).
The important bit is that the same callback must be used for Spring AOT "JVM" and Spring AOT "native". In the first case, the contribution is conditional while in the other it is invoked directly in the code for populating the bean definition and the instance supplier.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing RegisteredBean and BeanRegistrationCode APIs, especially the instance post-processor behavior, then compare the BeanFactoryPostProcessor and BeanPostProcessor paths described for Spring Data AOT repositories. Done means a new isolated callback can conditionally handle runtime-present beans, customize their bean definitions or instances, and be reused by Spring AOT JVM and native modes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100