-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Spring RestClient as TransportClientFactory #4281
base: main
Are you sure you want to change the base?
Changes from 9 commits
0a88c0f
783d4c1
142f1af
a9c6260
760dae3
1084cbc
b2c98b6
a6c2690
a9f8a23
6fd4f58
0ea8039
ac24e37
4c7ce21
871451c
e239d9b
8abfc6d
8581ab0
ffcff5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
import org.apache.commons.logging.LogFactory; | ||
|
||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.boot.autoconfigure.condition.AllNestedConditions; | ||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
|
@@ -73,10 +72,8 @@ public TlsProperties tlsProperties() { | |
|
||
@Bean | ||
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate") | ||
@Conditional(JerseyClientNotPresentOrNotEnabledCondition.class) | ||
@Conditional(RestTemplateEnabledCondition.class) | ||
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT) | ||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true, | ||
heowc marked this conversation as resolved.
Show resolved
Hide resolved
heowc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
havingValue = "false") | ||
public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(TlsProperties tlsProperties, | ||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier, | ||
ObjectProvider<RestTemplateBuilder> restTemplateBuilders) throws GeneralSecurityException, IOException { | ||
|
@@ -117,7 +114,7 @@ private static void setupTLS(AbstractDiscoveryClientOptionalArgs<?> args, TlsPro | |
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@Conditional(JerseyClientPresentAndEnabledCondition.class) | ||
@Conditional(RestTemplateEnabledCondition.class) | ||
@ConditionalOnBean(value = AbstractDiscoveryClientOptionalArgs.class, search = SearchStrategy.CURRENT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still want to keep the |
||
static class DiscoveryClientOptionalArgsTlsConfiguration { | ||
|
||
|
@@ -174,19 +171,27 @@ public WebClientNotFoundConfiguration() { | |
|
||
} | ||
|
||
static class JerseyClientPresentAndEnabledCondition extends AllNestedConditions { | ||
static class RestTemplateEnabledCondition extends AnyNestedCondition { | ||
|
||
JerseyClientPresentAndEnabledCondition() { | ||
RestTemplateEnabledCondition() { | ||
super(ConfigurationPhase.REGISTER_BEAN); | ||
} | ||
|
||
@ConditionalOnClass(name = "org.glassfish.jersey.client.JerseyClient") | ||
static class OnJerseyClientPresent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Jersey conditions are not related to the |
||
@ConditionalOnProperty(value = "eureka.client.jersey.enabled", matchIfMissing = true) | ||
static class OnJerseyClientEnabled { | ||
|
||
} | ||
|
||
@ConditionalOnProperty(value = "eureka.client.jersey.enabled", matchIfMissing = true) | ||
static class OnJerseyClientEnabled { | ||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true, | ||
havingValue = "false") | ||
static class OnWebClientDisabled { | ||
|
||
} | ||
|
||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true, | ||
havingValue = "false") | ||
static class OnRestClientDisabled { | ||
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.netflix.eureka.config; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.cloud.netflix.eureka.http.RestClientEurekaHttpClient; | ||
import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient; | ||
import org.springframework.cloud.test.ClassPathExclusions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
/** | ||
* @author Wonchul Heo | ||
*/ | ||
class EurekaConfigServerBootstrapConfigurationClientTests { | ||
|
||
@Test | ||
void properBeansCreatedWhenRestClientEnabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. Let's also add one that tests the |
||
new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) | ||
.withPropertyValues("spring.cloud.config.discovery.enabled=true") | ||
.withPropertyValues("eureka.client.enabled=true") | ||
.withPropertyValues("eureka.client.restclient.enabled=true") | ||
.run(context -> { | ||
assertThat(context).hasSingleBean(RestClientEurekaHttpClient.class); | ||
assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class); | ||
}); | ||
} | ||
|
||
@Test | ||
void properBeansCreatedWhenWebClientEnabled() { | ||
new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) | ||
.withPropertyValues("spring.cloud.config.discovery.enabled=true") | ||
.withPropertyValues("eureka.client.enabled=true") | ||
.withPropertyValues("eureka.client.webclient.enabled=true") | ||
.run(context -> { | ||
assertThat(context).hasSingleBean(WebClientEurekaHttpClient.class); | ||
assertThat(context).doesNotHaveBean(RestClientEurekaHttpClient.class); | ||
}); | ||
} | ||
|
||
@Nested | ||
@ClassPathExclusions({ "spring-webflux-*" }) | ||
static class NoWebFlux { | ||
|
||
@Test | ||
void properBeansCreatedWhenRestClientEnabled() { | ||
new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) | ||
.withPropertyValues("spring.cloud.config.discovery.enabled=true") | ||
.withPropertyValues("eureka.client.enabled=true") | ||
.withPropertyValues("eureka.client.restclient.enabled=true") | ||
.run(context -> { | ||
assertThat(context).hasSingleBean(RestClientEurekaHttpClient.class); | ||
assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class); | ||
}); | ||
} | ||
|
||
@Test | ||
void properBeansCreatedWhenWebEnabledThenFailed() { | ||
new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) | ||
.withPropertyValues("spring.cloud.config.discovery.enabled=true") | ||
.withPropertyValues("eureka.client.enabled=true") | ||
.withPropertyValues("eureka.client.webclient.enabled=true") | ||
.run(context -> { | ||
assertThatThrownBy(() -> context.getBean(WebClientEurekaHttpClient.class)) | ||
.hasRootCauseInstanceOf(NoSuchBeanDefinitionException.class) | ||
.hasRootCauseMessage( | ||
"No qualifying bean of type 'com.netflix.discovery.shared.transport.EurekaHttpClient' available: " | ||
+ "expected at least 1 bean which qualifies as autowire candidate. " | ||
+ "Dependency annotations: {}"); | ||
}); | ||
} | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still want to keep the
JerseyClientNotPresentOrNotEnabledCondition
here.