BeanCurrentlyInCreationException with DelegatingWebFluxConfiguration #25166
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
Uh oh!
There was an error while loading. Please reload this page.
DelegatingWebFluxConfiguration
can triggerBeanCurrentlyInCreationException
under a few circumstances.ReactiveAdapterRegistry
The first problem is that it is difficult to provide a
HandlerMethodArgumentResolver
that needs theReactiveAdapterRegistry
because this can cause a cycle depending on the order the beans are instantiated. For example, this test produces a cycle:authenticationPrincipalArgumentResolver
is requestedReactiveAdapterRegistry
which is a dependant beanReactiveAdapterRegistry
,DelegatingWebFluxConfiguration
needs to be created which requires allWebFluxConfigurer
instances to be wired into it.WebFluxConfigurer
instances. One of which isauthenticationPrincipalArgumentResolverConfigurer
which provides ourauthenticationPrincipalArgumentResolver
bean as an argument resolver.authenticationPrincipalArgumentResolver
which is a cycleOne option to make this less likely to happen is to define
authenticationPrincipalArgumentResolverConfigurer
as:This delays the lookup of
AuthenticationPrincipalArgumentResolver
. However, this has a few drawbacks.ArgumentResolverConfig
andWebFluxConfigurationSupport
.AuthenticationPrincipalArgumentResolver
configuration needingReactiveAdapterRegistry
(I'd argue that is pretty much everyAuthenticationPrincipalArgumentResolver
) to have the burden of fixing the issue rather than decoupling the beans (HandlerMethodArgumentResolver
andReactiveAdapterRegistry
) that are likely dependant on one another).We could move the delay inside
DelegatingWebFluxConfiguration
by autowiringObjectProvider<WebFluxConfigurer>
instead. However, this only fixes the second problem and leaves the cycle present.Another option is to make the definition of
ReactiveAdapterRegistry
a static method. This would ensure thatDelegatingWebFluxConfiguration
does not need to be instantiated. Yet another option would be to moveReactiveAdapterRegistry
to another configuration, but this could break other applications.ResourceUrlProvider Can Cause Early Initialization of DelegatingWebFluxConfiguration
ResourceUrlProvider
implementsApplicationListener
which can trigger early initialization ofDelegatingWebFluxConfiguration
. As soon as anApplicationEvent
is published, theApplicationListener
s need initialized. SinceResourceUrlProvider
is defined byDelegatingWebFluxConfiguration
it initializesDelegatingWebFluxConfiguration
and all of its dependant beans very early on.This is what is why the originally reported issue would happen in Boot 2.3.0 and not in previous versions. Specifically the changes for spring-projects/spring-boot#21325 moved the publishing of the
ReactiveWebServerInitializedEvent
from finishRefresh toSmartLifecycle
'sstart
method. This changed the order thatDelegatingWebFluxConfiguration
was created and triggered the bean cycle to happen.One solution is to move the
ResourceUrlProvider
bean definition to a static method.Related Issues
The text was updated successfully, but these errors were encountered: