Skip to content

Scope repeated Client resolution warning to the application context - #1417

Open
kdelay wants to merge 1 commit into
spring-cloud:5.0.xfrom
kdelay:fix/scope-client-init-warning-to-application-context
Open

kdelay wants to merge 1 commit into
spring-cloud:5.0.xfrom
kdelay:fix/scope-client-init-warning-to-application-context

Conversation

@kdelay

@kdelay kdelay commented Sep 11, 2026

Copy link
Copy Markdown

FeignClientFactoryBean tracks resolved context ids in a private static final Set, so the "is being initialized more than once. Ensure the Client bean is Singleton scoped" warning is JVM-wide and never cleared.

A second ApplicationContext in the same JVM, which is normal in a Spring Boot test suite or after @DirtiesContext, resolves the Client for a context id exactly once and still warns. The advice is wrong there: the bean is singleton scoped.

The detection is unchanged. The set is now per application context, keyed weakly on the owning BeanFactory so closed contexts are not retained.

FeignClientFactoryBeanTests covers both sides: a second resolution inside one context still warns, two separate contexts do not. The second test fails on main and passes here.

@ryanjbaxter

Copy link
Copy Markdown
Contributor

Can you submit this agains the 5.0.x branch?

The set of already resolved context ids was JVM wide and never cleared, so a
second ApplicationContext in the same JVM warned about repeated Client
initialization even though every context resolved the client exactly once.
Track the ids per application context instead, keyed weakly on the owning
BeanFactory so closed contexts are not retained.

Signed-off-by: kdelay <kdelay20@gmail.com>
@kdelay
kdelay force-pushed the fix/scope-client-init-warning-to-application-context branch from 16c6f00 to fddd1ee Compare September 16, 2026 00:48
@kdelay
kdelay changed the base branch from main to 5.0.x September 16, 2026 00:48
@kdelay

kdelay commented Sep 16, 2026

Copy link
Copy Markdown
Author

Retargeted to 5.0.x in fddd1ee. The commit cherry-picked cleanly. On 5.0.x the new test fails without the fix (FeignClientFactoryBeanTests.java:61, the captured log still contains the repeated-initialization warning) and passes with it; ./mvnw -pl spring-cloud-openfeign-core verify gives 443 tests, 0 failures, 0 checkstyle violations.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants