Skip to content

Recreate the scoped proxy of a changed @Configuration bean - #698

Open
kamilkrzywanski wants to merge 1 commit into
HotswapProjects:masterfrom
kamilkrzywanski:fix/393-scoped-proxy-recreate
Open

kamilkrzywanski wants to merge 1 commit into
HotswapProjects:masterfrom
kamilkrzywanski:fix/393-scoped-proxy-recreate

Conversation

@kamilkrzywanski

Copy link
Copy Markdown
Contributor

Refs #393

A scoped proxy @Bean (e.g. @SessionScope, or @Scope(proxyMode = TARGET_CLASS)) is registered as scopedTarget.name with the factory method and as name for the proxy (ScopedProxyFactoryBean). After a change of the @Configuration class, SpringBeanReload.resetConfigurationBeanDefinition removed only scopedTarget.name. When the configuration class was processed again, Spring saw the existing proxy definition and skipped the @Bean method, so every call through the proxy failed with No bean named 'scopedTarget.name' available.

Changes:

  • When scopedTarget.name is removed, also remove the proxy definition name if its targetBeanName is that target. Both are registered again from the configuration class. Beans that depend on the proxy are recreated, as for other @Bean methods of a changed configuration. A proxy instance kept elsewhere still works, it looks up the target by name.
  • Test with a thread scope instead of the session: after the change and after changing it back, the proxy works, a new scope gets the value of the changed @Bean method, and a plain @Bean of the same configuration is reloaded as before.

Tested with a Spring 6.2 application (@SessionScope-like scope with @Qualifier): before, every call failed after changing the configuration, now it works. Full build with tests passes on DCEVM 11.

This does not fix the startup error from #393 on Spring 5.3. That one comes from setCacheBeanMetadata(false), see #603.

A scoped proxy @bean (e.g. @SessionScope) is registered as
"scopedTarget.name" with the factory method and as "name" for the proxy.
After a change of the @configuration class the plugin removed only
"scopedTarget.name". When the @configuration class was processed again,
Spring saw the existing proxy definition and skipped the @bean method,
so every call through the proxy failed with "No bean named
'scopedTarget.name' available".

Remove the proxy definition together with its target.

Refs HotswapProjects#393

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant