Skip to content

Commit d531026

Browse files
committed
Backport: Remove dependency on enpoint bean in client
Since the actuator mvc endpoint beans live in a child context when the server and management port aren't the same, the admin client shouldn't depend on those beans. fixes codecentric#302
1 parent 91e79de commit d531026

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/config/AdminClientProperties.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.beans.factory.annotation.Autowired;
2424
import org.springframework.beans.factory.annotation.Value;
2525
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
26-
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
2726
import org.springframework.boot.autoconfigure.web.ServerProperties;
2827
import org.springframework.boot.context.event.ApplicationReadyEvent;
2928
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -61,8 +60,8 @@ public class AdminClientProperties {
6160
*/
6261
private boolean preferIp = false;
6362

64-
@Autowired
65-
private HealthMvcEndpoint healthEndpoint;
63+
@Value("${endpoints.health.path:/${endpoints.health.id:health}}")
64+
private String healthEndpointPath;
6665

6766
@Autowired
6867
private ManagementServerProperties management;
@@ -103,8 +102,8 @@ public String getManagementUrl() {
103102

104103
if (managementPort == null || managementPort.equals(serverPort)) {
105104
return UriComponentsBuilder.fromHttpUrl(getServiceUrl())
106-
.pathSegment(server.getServletPrefix())
107-
.pathSegment(trimLeadingCharacter(management.getContextPath(), '/'))
105+
.pathSegment(server.getServletPrefix().split("/"))
106+
.pathSegment(trimLeadingCharacter(management.getContextPath(), '/').split("/"))
108107
.toUriString();
109108
}
110109

@@ -117,7 +116,8 @@ public String getHealthUrl() {
117116
return healthUrl;
118117
}
119118
return UriComponentsBuilder.fromHttpUrl(getManagementUrl())
120-
.pathSegment(trimLeadingCharacter(healthEndpoint.getPath(), '/')).toUriString();
119+
.pathSegment(trimLeadingCharacter(healthEndpointPath, '/').split("/"))
120+
.toUriString();
121121
}
122122

123123
public void setManagementUrl(String managementUrl) {

spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/config/AdminClientPropertiesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ public void test_contextPath_mgmtPath() {
6767
@Test
6868
public void test_contextPatht_mgmtPortPath() {
6969
load("server.context-path=app", "management.context-path=/admin", "local.server.port=8080",
70-
"local.management.port=8081");
70+
"local.management.port=8081", "endpoints.health.path=/foo/bar");
7171
AdminClientProperties clientProperties = context.getBean(AdminClientProperties.class);
7272

7373
publishApplicationReadyEvent(clientProperties);
7474

7575
assertThat(clientProperties.getManagementUrl(),
7676
is("http://" + getHostname() + ":8081/admin"));
7777
assertThat(clientProperties.getHealthUrl(),
78-
is("http://" + getHostname() + ":8081/admin/health"));
78+
is("http://" + getHostname() + ":8081/admin/foo/bar"));
7979
assertThat(clientProperties.getServiceUrl(), is("http://" + getHostname() + ":8080/app"));
8080
}
8181

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package de.codecentric.boot.admin.config;
2+
3+
import static org.hamcrest.Matchers.notNullValue;
4+
import static org.junit.Assert.assertThat;
5+
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
10+
import org.springframework.boot.test.SpringApplicationConfiguration;
11+
import org.springframework.boot.test.WebIntegrationTest;
12+
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
14+
15+
@RunWith(SpringJUnit4ClassRunner.class)
16+
@SpringApplicationConfiguration(classes = TestClientApplication.class)
17+
@WebIntegrationTest(randomPort = true, value = { "management.port=0",
18+
"spring.boot.admin.url=http://example.com" })
19+
public class ClientApplicationTest {
20+
21+
@Autowired
22+
private AdminProperties properties;
23+
24+
@Test
25+
public void test_context() {
26+
assertThat(properties, notNullValue());
27+
}
28+
}
29+
30+
@Configuration
31+
@EnableAutoConfiguration
32+
class TestClientApplication {
33+
}

spring-boot-admin-starter-client/src/test/resources/logback-test.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/base.xml" />
34
<root level="INFO">
45
<appender-ref ref="CONSOLE" />
56
</root>

0 commit comments

Comments
 (0)