Many Spring Cloud Projects heavily rely on child contexts. This is currently not supported by AOT. The issue was raised before in the spring-native repo, however, a decision has been taken to move it over to Spring Framework 6 backlog.
Comment From: snicoll
I don't think the API as it is would not let you support this. A lot of the complexity resides in what actually uses the child application contexts. The main context is processed automatically by the AOT engine because we're in control of its lifecycle. The child contexts that are described in the issue you referenced are created programmatically and out of framework's control.
To be able to support this in AOT, these are the things that need to be done:
- Adapt the existing code so that the required contexts can be parsed. For
NamedContextFactoryBean
, the specification beans must be instantiated at build-time so we might need to reconsider that model if we want to make sure users don't inject beans they shouldn't - Based on the specification, create an
ApplicationContext
(without refreshing it) - Process the context with AOT, and store its "identity"
- Contribute a
NamedContextFactoryBean
that uses the generated context instead of doing the parsing
In this list, 1 & 2 are Spring Cloud specific and this work can start right now. 4 is a custom code contributor that is possible with the current API. As for 3, it is also possible but we may need to brainstorm a bit to see if we can improve the API.
Does the above match your expectation?
Comment From: snicoll
To support the above, this comment describes how we attempt to integrate the management child context in Spring Boot.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: OlgaMaciaszek
Thanks, @snicoll. As discussed we're going to take a shot at generating the bean definition maps and consider the possible issues of this approach, including resolving default specifications and not creating Specification
beans and get back to you.
Comment From: onobc
[TinyNit] Can someone add the "theme:aot" label?
Comment From: OlgaMaciaszek
Support necessary for projects to create child contexts in AOT is now available in Framework. See https://github.com/spring-cloud/spring-cloud-commons/pull/1135 for an implementation example.