Skip to content

Exclude @LoadBalanced RestClient/WebClient builders from Eureka transport - #4602

Open
arimu1 wants to merge 1 commit into
spring-cloud:mainfrom
arimu1:fix/4591-eureka-skip-loadbalanced-restclient
Open

arimu1 wants to merge 1 commit into
spring-cloud:mainfrom
arimu1:fix/4591-eureka-skip-loadbalanced-restclient

Conversation

@arimu1

@arimu1 arimu1 commented Sep 13, 2026

Copy link
Copy Markdown

Summary

  • Resolve Eureka registry RestClient.Builder / WebClient.Builder candidates by excluding beans annotated with @LoadBalanced, so calls to the Eureka server URL are not routed through the load balancer (fixes No instances available for localhost when only a load-balanced builder is registered).
  • Fall back to RestClient.builder() / WebClient.builder() when every registered builder is load-balanced.
  • Add context tests covering RestClient-only, plain+load-balanced, and WebClient-only setups.

Fixes gh-4591 (same root cause as gh-4524).

Test plan

  • ./mvnw -pl spring-cloud-netflix-eureka-client -Dtest=LoadBalancedEurekaHttpClientBuilderConfigurationTests test (JDK 21)
  • ./mvnw -pl spring-cloud-netflix-eureka-client -am test — module suite passes except pre-existing EurekaConfigServerBootstrapperIntegrationTests (Docker not available locally)

Eureka registry calls must not use load-balanced RestClient or WebClient
builders. Filter @LoadBalanced beans when resolving builders and fall back
to plain factory methods when needed.

Fixes spring-cloudgh-4591

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>

private static <T> T resolveNonLoadBalancedBuilder(ConfigurableListableBeanFactory beanFactory, Class<T> type,
Supplier<T> fallback) {
for (String name : beanFactory.getBeanNamesForType(type)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selected bean ignores @Order/@Priority of beans

return () -> resolveNonLoadBalancedBuilder(beanFactory, WebClient.Builder.class, WebClient::builder);
}

private static <T> T resolveNonLoadBalancedBuilder(ConfigurableListableBeanFactory beanFactory, Class<T> type,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only needs to happen once, and not once right now it happens on every EurekaClient creation

}

@Test
void restClientTransportPrefersPlainRestClientBuilderOverLoadBalanced() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebClient should have a similar test

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.

@LoadBalanced with RestClient` — the problem and the fix

3 participants