Skip to content

Commit

Permalink
Revert making RestClient the default Eureka client. Fixes gh-4380.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMaciaszek committed Dec 2, 2024
1 parent 9c5b39e commit 8e04fc5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
8 changes: 6 additions & 2 deletions docs/modules/ROOT/pages/spring-cloud-netflix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ It is initialized in a `SmartLifecycle` (with `phase=0`), so the earliest you ca

`EurekaClient` uses either `RestClient`, `RestTemplate`, `WebClient` or `JerseyClient` under the hood. In order to use the `EurekaClient`, you need to have one of the supported HTTP clients on your classpath.

To use `RestTemplate` or `RestClient`, add `spring-boot-starter-web` to your dependencies. To use `WebClient`, add `spring-boot-starter-webflux` to your dependencies. If both `spring-boot-starter-web` and `spring-boot-starter-webflux` are included in the dependencies and the `eureka.client.webclient.enabled` flag is set to `true`, then `WebClient` will be used. If that's not the case and `eureka.client.restclient.enabled` is set to false, the `RestTemplate` will be used. Otherwise, the `RestClient` will be used.
To use `RestTemplate` or `RestClient`, add `spring-boot-starter-web` to your dependencies. To use `WebClient`, add `spring-boot-starter-webflux` to your dependencies. If both `spring-boot-starter-web`
and `spring-boot-starter-webflux` are included in the dependencies and the `eureka.client.webclient.enabled` flag is set to `true`,
then `WebClient` will be used. If that's not the case and `eureka.client.restclient.enabled` is set to `true`, `RestClient` will be used. Otherwise, `RestTemplate` will be used.

NOTE: Starting from 4.2.0, the default client has changed to `RestClient`.
NOTE: For any of those client implementations, if there's a builder bean available, it will be used to create the underlying client.

NOTE: We're planning on changing the default client to `RestClient` with the next major release.

If you wish to use Jersey instead, you need to add the Jersey dependencies to your classpath.
The following example shows the dependencies you need to add:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ static class OnWebClientDisabled {

}

@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false",
matchIfMissing = true)
static class OnRestClientDisabled {

}
Expand Down Expand Up @@ -311,8 +312,7 @@ static class OnWebClientDisabled {

}

@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true,
havingValue = "true")
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")
static class OnRestClientEnabled {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ static class OnWebClientDisabled {

}

@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false",
matchIfMissing = true)
static class OnRestClientDisabled {

}
Expand Down Expand Up @@ -194,8 +195,7 @@ static class OnWebClientDisabled {

}

@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true,
havingValue = "true")
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")
static class OnRestClientEnabled {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.cloud.netflix.eureka.http.RestClientEurekaHttpClient;
import org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.annotation.Bean;
Expand All @@ -53,6 +53,7 @@
* @author Spencer Gibb
* @author Tang Xiong
*/
@SuppressWarnings("removal")
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("spring-webflux-*")
public class EurekaConfigServerBootstrapConfigurationTests {
Expand Down Expand Up @@ -205,7 +206,7 @@ public void eurekaConfigServerInstanceProviderCalledWithVipAddress() {

private void assertEurekaBeansPresent(AssertableApplicationContext context) {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).hasSingleBean(RestClientEurekaHttpClient.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,14 +22,15 @@
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.cloud.netflix.eureka.http.RestClientEurekaHttpClient;
import org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient;
import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Spencer Gibb
*/
@SuppressWarnings("removal")
class EurekaConfigServerBootstrapConfigurationWebClientTests {

@Test
Expand All @@ -53,7 +54,7 @@ void properBeansCreatedWhenEnabledWebClientDisabled() {
.run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class);
assertThat(context).hasSingleBean(RestClientEurekaHttpClient.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.netflix.eureka.http.RestClientDiscoveryClientOptionalArgs;
import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -30,11 +30,12 @@
*
* @author Olga Maciaszek-Sharma
*/
@SuppressWarnings("deprecation")
public class JerseyClientOptionalArgsConfigurationTests {

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
void shouldCreateRestClientDiscoveryClientOptionalArgsWhenJerseyClientDisabled() {
void shouldCreateRestTemplateDiscoveryClientOptionalArgsWhenJerseyClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(DiscoveryClientOptionalArgsConfiguration.class))
.withPropertyValues("eureka.client.jersey.enabled=false")
Expand All @@ -44,8 +45,8 @@ void shouldCreateRestClientDiscoveryClientOptionalArgsWhenJerseyClientDisabled()
.values()
.stream()
.findFirst()
.get()).isInstanceOf(RestClientDiscoveryClientOptionalArgs.class);
assertThat(context).hasSingleBean(RestClientDiscoveryClientOptionalArgs.class);
.get()).isInstanceOf(RestTemplateDiscoveryClientOptionalArgs.class);
assertThat(context).hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
});
}

Expand Down

0 comments on commit 8e04fc5

Please sign in to comment.