Skip to content

Commit 3ec5fe9

Browse files
committed
disable refresh by default
1 parent dafd848 commit 3ec5fe9

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

src/main/java/com/freemanan/starter/httpexchange/HttpClientBeanRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void registerHttpClientBean(BeanDefinitionRegistry registry, String class
105105
abd.setLazyInit(true);
106106

107107
try {
108-
if (SPRING_CLOUD_CONTEXT_PRESENT) {
108+
if (properties.getRefresh().isEnabled() && SPRING_CLOUD_CONTEXT_PRESENT) {
109109
abd.setScope("refresh");
110110
BeanDefinitionHolder scopedProxy =
111111
ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(abd, className), registry, false);

src/main/java/com/freemanan/starter/httpexchange/HttpClientsProperties.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ public class HttpClientsProperties implements InitializingBean {
4747
* Default headers, will be added to all the requests.
4848
*/
4949
private List<Header> headers = new ArrayList<>();
50-
50+
/**
51+
* Channels configuration.
52+
*/
5153
private List<Channel> channels = new ArrayList<>();
52-
5354
/**
5455
* Whether to convert Java bean to query parameters, default value is {@code false}.
5556
*/
5657
private boolean beanToQuery = false;
58+
/**
59+
* Refresh configuration.
60+
*/
61+
private Refresh refresh = new Refresh();
5762

5863
@Data
5964
@NoArgsConstructor
@@ -142,4 +147,15 @@ public static class Channel {
142147
*/
143148
private List<Class<?>> classes = new ArrayList<>();
144149
}
150+
151+
@Data
152+
public static class Refresh {
153+
public static final String PREFIX = HttpClientsProperties.PREFIX + ".refresh";
154+
/**
155+
* Whether to enable refresh exchange clients, default {@code false}.
156+
*
157+
* <p> NOTE: this feature needs {@code spring-cloud-context} dependency in the classpath.
158+
*/
159+
private boolean enabled = false;
160+
}
145161
}

src/test/java/com/freemanan/starter/httpexchange/DynamicRefreshTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ void testDynamicRefresh() {
2727
var ctx = new SpringApplicationBuilder(Cfg.class)
2828
.properties("server.port=" + port)
2929
.properties("http-exchange.base-url=http://localhost:" + port)
30+
.properties("http-exchange.refresh.enabled=true")
3031
.run();
3132

33+
// 3 beans: controller bean, api bean, proxied api bean
34+
assertThat(ctx.getBeanProvider(FooApi.class)).hasSize(3);
35+
3236
FooApi api = ctx.getBean(FooApi.class);
37+
3338
assertThat(api.get()).isEqualTo("OK");
3439

3540
System.setProperty("http-exchange.base-url", "http://localhost:" + port + "/v2");

src/test/java/com/freemanan/starter/httpexchange/ExtendShadedTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void userApiFirst_whenHaveControllerAndApiBeans() {
3737
.properties("server.port=" + port)
3838
.run();
3939
long count = ctx.getBeanProvider(FooApi.class).stream().count();
40-
assertThat(count).isEqualTo(3);
40+
assertThat(count).isEqualTo(2);
4141

4242
FooApi fooApi = ctx.getBean(FooApi.class);
4343
assertThat(fooApi).isNotInstanceOf(FooController.class);

src/test/java/com/freemanan/starter/httpexchange/ExtendTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void userApiFirst_whenHaveControllerAndApiBeans() {
3434
.profiles("ControllerApiTests")
3535
.properties("server.port=" + port)
3636
.run();
37-
assertThat(ctx.getBeanProvider(FooApi.class)).hasSize(3);
37+
assertThat(ctx.getBeanProvider(FooApi.class)).hasSize(2);
3838

3939
FooApi fooApi = ctx.getBean(FooApi.class);
4040
assertThat(fooApi).isNotInstanceOf(FooController.class);

0 commit comments

Comments
 (0)