spring-projects / spring-projects/spring-framework

Introduce a new hook point for Optimizing a Bean if it is present at runtime

Open
#35,500 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core status: pending-design-work theme: aot type: enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.