Commit d5310269 by Johannes Edmeier

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 #302
parent 91e79dea
......@@ -23,7 +23,6 @@ import java.net.UnknownHostException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -61,8 +60,8 @@ public class AdminClientProperties {
*/
private boolean preferIp = false;
@Autowired
private HealthMvcEndpoint healthEndpoint;
@Value("${endpoints.health.path:/${endpoints.health.id:health}}")
private String healthEndpointPath;
@Autowired
private ManagementServerProperties management;
......@@ -103,8 +102,8 @@ public class AdminClientProperties {
if (managementPort == null || managementPort.equals(serverPort)) {
return UriComponentsBuilder.fromHttpUrl(getServiceUrl())
.pathSegment(server.getServletPrefix())
.pathSegment(trimLeadingCharacter(management.getContextPath(), '/'))
.pathSegment(server.getServletPrefix().split("/"))
.pathSegment(trimLeadingCharacter(management.getContextPath(), '/').split("/"))
.toUriString();
}
......@@ -117,7 +116,8 @@ public class AdminClientProperties {
return healthUrl;
}
return UriComponentsBuilder.fromHttpUrl(getManagementUrl())
.pathSegment(trimLeadingCharacter(healthEndpoint.getPath(), '/')).toUriString();
.pathSegment(trimLeadingCharacter(healthEndpointPath, '/').split("/"))
.toUriString();
}
public void setManagementUrl(String managementUrl) {
......
......@@ -67,7 +67,7 @@ public class AdminClientPropertiesTest {
@Test
public void test_contextPatht_mgmtPortPath() {
load("server.context-path=app", "management.context-path=/admin", "local.server.port=8080",
"local.management.port=8081");
"local.management.port=8081", "endpoints.health.path=/foo/bar");
AdminClientProperties clientProperties = context.getBean(AdminClientProperties.class);
publishApplicationReadyEvent(clientProperties);
......@@ -75,7 +75,7 @@ public class AdminClientPropertiesTest {
assertThat(clientProperties.getManagementUrl(),
is("http://" + getHostname() + ":8081/admin"));
assertThat(clientProperties.getHealthUrl(),
is("http://" + getHostname() + ":8081/admin/health"));
is("http://" + getHostname() + ":8081/admin/foo/bar"));
assertThat(clientProperties.getServiceUrl(), is("http://" + getHostname() + ":8080/app"));
}
......
package de.codecentric.boot.admin.config;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestClientApplication.class)
@WebIntegrationTest(randomPort = true, value = { "management.port=0",
"spring.boot.admin.url=http://example.com" })
public class ClientApplicationTest {
@Autowired
private AdminProperties properties;
@Test
public void test_context() {
assertThat(properties, notNullValue());
}
}
@Configuration
@EnableAutoConfiguration
class TestClientApplication {
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment