Merge branch '1.2.x'
This commit is contained in:
commit
43c5151ee1
|
|
@ -26,11 +26,13 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties for the management server (e.g. port and path settings).
|
* Properties for the management server (e.g. port and path settings).
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Stephane Nicoll
|
||||||
* @see ServerProperties
|
* @see ServerProperties
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "management", ignoreUnknownFields = true)
|
@ConfigurationProperties(prefix = "management", ignoreUnknownFields = true)
|
||||||
|
|
@ -103,12 +105,22 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the context path with no trailing slash (i.e. the '/' root context is
|
||||||
|
* represented as the empty string).
|
||||||
|
* @return the context path (no trailing slash)
|
||||||
|
*/
|
||||||
public String getContextPath() {
|
public String getContextPath() {
|
||||||
return this.contextPath;
|
return this.contextPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContextPath(String contextPath) {
|
public void setContextPath(String contextPath) {
|
||||||
this.contextPath = contextPath;
|
if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) {
|
||||||
|
this.contextPath = contextPath.substring(0, contextPath.length() - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.contextPath = contextPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Security getSecurity() {
|
public Security getSecurity() {
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,6 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure;
|
package org.springframework.boot.actuate.autoconfigure;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
|
@ -29,37 +26,38 @@ import static org.junit.Assert.assertThat;
|
||||||
* Tests for {@link ManagementServerPropertiesAutoConfiguration}.
|
* Tests for {@link ManagementServerPropertiesAutoConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class ManagementServerPropertiesAutoConfigurationTests {
|
public class ManagementServerPropertiesAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultManagementServerProperties() {
|
public void defaultManagementServerProperties() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
ManagementServerPropertiesAutoConfiguration.class);
|
assertThat(properties.getPort(), nullValue());
|
||||||
assertThat(context.getBean(ManagementServerProperties.class).getPort(),
|
assertThat(properties.getContextPath(), equalTo(""));
|
||||||
nullValue());
|
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void definedManagementServerProperties() throws Exception {
|
public void definedManagementServerProperties() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
Config.class, ManagementServerPropertiesAutoConfiguration.class);
|
properties.setPort(123);
|
||||||
assertThat(context.getBean(ManagementServerProperties.class).getPort(),
|
properties.setContextPath("/foo");
|
||||||
equalTo(Integer.valueOf(123)));
|
assertThat(properties.getPort(), equalTo(123));
|
||||||
context.close();
|
assertThat(properties.getContextPath(), equalTo("/foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Test
|
||||||
public static class Config {
|
public void trailingSlashOfContextPathIsRemoved() {
|
||||||
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
@Bean
|
properties.setContextPath("/foo/");
|
||||||
public ManagementServerProperties managementServerProperties() {
|
assertThat(properties.getContextPath(), equalTo("/foo"));
|
||||||
ManagementServerProperties properties = new ManagementServerProperties();
|
}
|
||||||
properties.setPort(123);
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void slashOfContextPathIsDefaultValue() {
|
||||||
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
|
properties.setContextPath("/");
|
||||||
|
assertThat(properties.getContextPath(), equalTo(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue