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.

Comment From: SuganthiThomas

Hi, I’m interested in working on this issue. I have experience with Java and Spring Boot. Could I take this up?