Introduce "server.servlet" configuration prefix
This commit refactors the `ServerProperties` property keys and introduces a separate "server.servlet" namespace to isolate servlet-specific properties from the rest. Closes gh-8066
This commit is contained in:
@@ -38,7 +38,7 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
|
||||
|
||||
private final String scheme;
|
||||
|
||||
private RelaxedPropertyResolver serverPropertyResolver;
|
||||
private RelaxedPropertyResolver servletPropertyResolver;
|
||||
|
||||
/**
|
||||
* Create a new {@code LocalHostUriTemplateHandler} that will generate {@code http}
|
||||
@@ -63,13 +63,13 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
|
||||
Assert.notNull(scheme, "Scheme must not be null");
|
||||
this.environment = environment;
|
||||
this.scheme = scheme;
|
||||
this.serverPropertyResolver = new RelaxedPropertyResolver(environment, "server.");
|
||||
this.servletPropertyResolver = new RelaxedPropertyResolver(environment, "server.servlet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRootUri() {
|
||||
String port = this.environment.getProperty("local.server.port", "8080");
|
||||
String contextPath = this.serverPropertyResolver.getProperty("context-path", "");
|
||||
String contextPath = this.servletPropertyResolver.getProperty("context-path", "");
|
||||
return this.scheme + "://localhost:" + port + contextPath;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class LocalHostUriTemplateHandlerTests {
|
||||
@Test
|
||||
public void getRootUriShouldUseContextPath() throws Exception {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("server.contextPath", "/foo");
|
||||
environment.setProperty("server.servlet.context-path", "/foo");
|
||||
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
|
||||
environment);
|
||||
assertThat(handler.getRootUri()).isEqualTo("http://localhost:8080/foo");
|
||||
|
||||
Reference in New Issue
Block a user