You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A consequence of this is that the use of AOT changes the state of the context when the other initialisers are called. In the standard non-AOT case, the other initializers see an almost empty context that only contains its standard beans. In the AOT case, the other initializers see all of the application's bean. We should try to address this and reduce the difference between the two. The simplest option would be to add the AOT initializer last so that it runs after any other initializers but this doesn't minimise the difference.
In the standard case, the application's beans start to appear in the context when SpringApplication loads the sources. This is done towards the end of prepareContext and immediately before contextLoaded is called on the run listeners. This will typically result in the application's main class being registered as a bean. All of the other beans are then registered as part of refreshing the context which SpringApplication does immediately after calling contextLoaded. In the AOT case, where the initialization happens much earlier, all of the application's beans are visible to:
All other context initializers
The context prepared callback, including listeners to the ApplicationContextInitializedEvent
The context loaded callback, including listeners to the ApplicationPreparedEvent
To minimise the difference between the standard case and the AOT case, I think the AOT initializer should be applied to the context either immediately before contextLoaded is called on the run listeners or immediately before refresh is called on the context. The former will result in the listeners seeing more beans in the context in the AOT case. The latter will result in the listeners not seeing the beans for the application's sources in the AOT case.
The text was updated successfully, but these errors were encountered:
If we change anything here, we need to keep #41562 in mind. Right now, the AOT initializer configures the environment's active profiles so that a profile that was active at build time is also active at runtime. It's already happening too late to influence config data loading. Either of the changes discussed above would make it happen even later and may create other problems.
We currently add a custom initialiser for AOT and place it first in the application's list of initializers:
spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
Lines 437 to 449 in 12ec18f
A consequence of this is that the use of AOT changes the state of the context when the other initialisers are called. In the standard non-AOT case, the other initializers see an almost empty context that only contains its standard beans. In the AOT case, the other initializers see all of the application's bean. We should try to address this and reduce the difference between the two. The simplest option would be to add the AOT initializer last so that it runs after any other initializers but this doesn't minimise the difference.
In the standard case, the application's beans start to appear in the context when
SpringApplication
loads the sources. This is done towards the end ofprepareContext
and immediately beforecontextLoaded
is called on the run listeners. This will typically result in the application's main class being registered as a bean. All of the other beans are then registered as part of refreshing the context whichSpringApplication
does immediately after callingcontextLoaded
. In the AOT case, where the initialization happens much earlier, all of the application's beans are visible to:ApplicationContextInitializedEvent
ApplicationPreparedEvent
To minimise the difference between the standard case and the AOT case, I think the AOT initializer should be applied to the context either immediately before
contextLoaded
is called on the run listeners or immediately beforerefresh
is called on the context. The former will result in the listeners seeing more beans in the context in the AOT case. The latter will result in the listeners not seeing the beans for the application's sources in the AOT case.The text was updated successfully, but these errors were encountered: