Revert making RestClient the default Eureka client. Fixes gh-4380.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -282,7 +282,8 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false",
|
||||
matchIfMissing = true)
|
||||
static class OnRestClientDisabled {
|
||||
|
||||
}
|
||||
@@ -311,8 +312,7 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true,
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")
|
||||
static class OnRestClientEnabled {
|
||||
|
||||
}
|
||||
|
||||
@@ -129,7 +129,8 @@ public class EurekaConfigServerBootstrapConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false",
|
||||
matchIfMissing = true)
|
||||
static class OnRestClientDisabled {
|
||||
|
||||
}
|
||||
@@ -194,8 +195,7 @@ public class EurekaConfigServerBootstrapConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true,
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")
|
||||
static class OnRestClientEnabled {
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
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;
|
||||
@@ -53,6 +53,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Spencer Gibb
|
||||
* @author Tang Xiong
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ClassPathExclusions("spring-webflux-*")
|
||||
public class EurekaConfigServerBootstrapConfigurationTests {
|
||||
@@ -205,7 +206,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
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;
|
||||
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class EurekaConfigServerBootstrapConfigurationWebClientTests {
|
||||
|
||||
@Test
|
||||
@@ -53,7 +54,7 @@ class EurekaConfigServerBootstrapConfigurationWebClientTests {
|
||||
.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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
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;
|
||||
|
||||
@@ -30,11 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @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")
|
||||
@@ -44,8 +45,8 @@ public class JerseyClientOptionalArgsConfigurationTests {
|
||||
.values()
|
||||
.stream()
|
||||
.findFirst()
|
||||
.get()).isInstanceOf(RestClientDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context).hasSingleBean(RestClientDiscoveryClientOptionalArgs.class);
|
||||
.get()).isInstanceOf(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
assertThat(context).hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user