Move WebServer-specific properties out of ManagementServerProperties

Issue: 44324
This commit is contained in:
Andy Wilkinson
2025-02-18 12:55:55 +00:00
committed by Phillip Webb
parent 39b7c85a73
commit 4ce7a14b25
17 changed files with 286 additions and 100 deletions

View File

@@ -58,12 +58,6 @@ public class ManagementServerProperties {
@NestedConfigurationProperty
private Ssl ssl;
private final Jetty jetty = new Jetty();
private final Tomcat tomcat = new Tomcat();
private final Undertow undertow = new Undertow();
/**
* Returns the management port or {@code null} if the
* {@link ServerProperties#getPort() server port} should be used.
@@ -108,18 +102,6 @@ public class ManagementServerProperties {
this.ssl = ssl;
}
public Jetty getJetty() {
return this.jetty;
}
public Tomcat getTomcat() {
return this.tomcat;
}
public Undertow getUndertow() {
return this.undertow;
}
private String cleanBasePath(String basePath) {
String candidate = null;
if (StringUtils.hasLength(basePath)) {
@@ -136,51 +118,4 @@ public class ManagementServerProperties {
return candidate;
}
public static class Jetty {
private final Accesslog accesslog = new Accesslog();
public Accesslog getAccesslog() {
return this.accesslog;
}
}
public static class Tomcat {
private final Accesslog accesslog = new Accesslog();
public Accesslog getAccesslog() {
return this.accesslog;
}
}
public static class Undertow {
private final Accesslog accesslog = new Accesslog();
public Accesslog getAccesslog() {
return this.accesslog;
}
}
public static class Accesslog {
/**
* Management log file name prefix.
*/
private String prefix = "management_";
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
}

View File

@@ -24,7 +24,6 @@ import org.eclipse.jetty.server.RequestLogWriter;
import org.eclipse.jetty.server.Server;
import org.springframework.boot.actuate.autoconfigure.web.server.AccessLogCustomizer;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.server.jetty.ConfigurableJettyWebServerFactory;
import org.springframework.util.StringUtils;
@@ -37,8 +36,8 @@ import org.springframework.util.StringUtils;
class JettyAccessLogCustomizer extends AccessLogCustomizer<ConfigurableJettyWebServerFactory>
implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {
JettyAccessLogCustomizer(ManagementServerProperties properties) {
super(properties.getJetty().getAccesslog().getPrefix());
JettyAccessLogCustomizer(JettyManagementServerProperties properties) {
super(properties.getAccesslog().getPrefix());
}
@Override

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.web.server.jetty;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties for a Jetty-based management server.
*
* @author Moritz Halbritter
* @since 4.0.0
*/
@ConfigurationProperties("management.server.jetty")
public class JettyManagementServerProperties {
private final Accesslog accesslog = new Accesslog();
public Accesslog getAccesslog() {
return this.accesslog;
}
public static class Accesslog {
/**
* Management log file name prefix.
*/
private String prefix = "management_";
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
}

View File

@@ -20,7 +20,6 @@ import org.eclipse.jetty.server.Server;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -36,12 +35,12 @@ import org.springframework.context.annotation.Bean;
*/
@ConditionalOnClass(Server.class)
@ConditionalOnWebApplication(type = Type.REACTIVE)
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties(JettyManagementServerProperties.class)
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
class JettyReactiveManagementChildContextConfiguration {
@Bean
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) {
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(JettyManagementServerProperties properties) {
return new JettyAccessLogCustomizer(properties);
}

View File

@@ -20,7 +20,6 @@ import org.eclipse.jetty.server.Server;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -36,12 +35,12 @@ import org.springframework.context.annotation.Bean;
*/
@ConditionalOnClass(Server.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties(JettyManagementServerProperties.class)
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
class JettyServletManagementChildContextConfiguration {
@Bean
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) {
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(JettyManagementServerProperties properties) {
return new JettyAccessLogCustomizer(properties);
}

View File

@@ -23,7 +23,6 @@ import org.apache.catalina.Valve;
import org.apache.catalina.valves.AccessLogValve;
import org.springframework.boot.actuate.autoconfigure.web.server.AccessLogCustomizer;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.web.server.tomcat.ConfigurableTomcatWebServerFactory;
/**
@@ -36,9 +35,9 @@ class TomcatAccessLogCustomizer<T extends ConfigurableTomcatWebServerFactory> ex
private final Function<T, Collection<Valve>> engineValvesExtractor;
TomcatAccessLogCustomizer(ManagementServerProperties properties,
TomcatAccessLogCustomizer(TomcatManagementServerProperties properties,
Function<T, Collection<Valve>> engineValvesExtractor) {
super(properties.getTomcat().getAccesslog().getPrefix());
super(properties.getAccesslog().getPrefix());
this.engineValvesExtractor = engineValvesExtractor;
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.web.server.tomcat;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties for a Tomcat-based management server.
*
* @author Moritz Halbritter
* @since 4.0.0
*/
@ConfigurationProperties("management.server.tomcat")
public class TomcatManagementServerProperties {
private final Accesslog accesslog = new Accesslog();
public Accesslog getAccesslog() {
return this.accesslog;
}
public static class Accesslog {
/**
* Management log file name prefix.
*/
private String prefix = "management_";
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
}

View File

@@ -20,7 +20,6 @@ import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -37,13 +36,13 @@ import org.springframework.context.annotation.Bean;
*/
@ConditionalOnClass(Tomcat.class)
@ConditionalOnWebApplication(type = Type.REACTIVE)
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties(TomcatManagementServerProperties.class)
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
class TomcatReactiveManagementChildContextConfiguration {
@Bean
TomcatAccessLogCustomizer<TomcatReactiveWebServerFactory> tomcatManagementAccessLogCustomizer(
ManagementServerProperties properties) {
TomcatManagementServerProperties properties) {
return new TomcatAccessLogCustomizer<>(properties, TomcatReactiveWebServerFactory::getEngineValves);
}

View File

@@ -20,7 +20,6 @@ import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -37,13 +36,13 @@ import org.springframework.context.annotation.Bean;
*/
@ConditionalOnClass(Tomcat.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties(TomcatManagementServerProperties.class)
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
class TomcatServletManagementChildContextConfiguration {
@Bean
TomcatAccessLogCustomizer<TomcatServletWebServerFactory> tomcatManagementAccessLogCustomizer(
ManagementServerProperties properties) {
TomcatManagementServerProperties properties) {
return new TomcatAccessLogCustomizer<>(properties, TomcatServletWebServerFactory::getEngineValves);
}

View File

@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.web.server.undertow;
import java.util.function.Function;
import org.springframework.boot.actuate.autoconfigure.web.server.AccessLogCustomizer;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.web.server.undertow.ConfigurableUndertowWebServerFactory;
/**
@@ -32,8 +31,9 @@ class UndertowAccessLogCustomizer<T extends ConfigurableUndertowWebServerFactory
private final Function<T, String> accessLogPrefixExtractor;
UndertowAccessLogCustomizer(ManagementServerProperties properties, Function<T, String> accessLogPrefixExtractor) {
super(properties.getUndertow().getAccesslog().getPrefix());
UndertowAccessLogCustomizer(UndertowManagementServerProperties properties,
Function<T, String> accessLogPrefixExtractor) {
super(properties.getAccesslog().getPrefix());
this.accessLogPrefixExtractor = accessLogPrefixExtractor;
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.web.server.undertow;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Properties for an Undertow-based management server.
*
* @author Moritz Halbritter
* @since 4.0.0
*/
@ConfigurationProperties("management.server.undertow")
public class UndertowManagementServerProperties {
private final Accesslog accesslog = new Accesslog();
public Accesslog getAccesslog() {
return this.accesslog;
}
public static class Accesslog {
/**
* Management log file name prefix.
*/
private String prefix = "management_";
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
}

View File

@@ -22,7 +22,6 @@ import org.springframework.boot.WebApplicationType;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextFactory;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -41,7 +40,7 @@ import org.springframework.context.annotation.Bean;
*/
@ConditionalOnClass(Undertow.class)
@ConditionalOnWebApplication(type = Type.REACTIVE)
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties(UndertowManagementServerProperties.class)
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
class UndertowReactiveManagementChildContextConfiguration {
@@ -53,7 +52,7 @@ class UndertowReactiveManagementChildContextConfiguration {
@Bean
UndertowAccessLogCustomizer<UndertowReactiveWebServerFactory> undertowManagementAccessLogCustomizer(
ManagementServerProperties properties) {
UndertowManagementServerProperties properties) {
return new UndertowAccessLogCustomizer<>(properties, UndertowReactiveWebServerFactory::getAccessLogPrefix);
}

View File

@@ -20,7 +20,6 @@ import io.undertow.Undertow;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@@ -37,13 +36,13 @@ import org.springframework.context.annotation.Bean;
*/
@ConditionalOnClass(Undertow.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties(UndertowManagementServerProperties.class)
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
class UndertowServletManagementChildContextConfiguration {
@Bean
UndertowAccessLogCustomizer<UndertowServletWebServerFactory> undertowManagementAccessLogCustomizer(
ManagementServerProperties properties) {
UndertowManagementServerProperties properties) {
return new UndertowAccessLogCustomizer<>(properties, UndertowServletWebServerFactory::getAccessLogPrefix);
}

View File

@@ -69,12 +69,4 @@ class ManagementServerPropertiesTests {
assertThat(properties.getBasePath()).isEmpty();
}
@Test
void accessLogsArePrefixedByDefault() {
ManagementServerProperties properties = new ManagementServerProperties();
assertThat(properties.getTomcat().getAccesslog().getPrefix()).isEqualTo("management_");
assertThat(properties.getJetty().getAccesslog().getPrefix()).isEqualTo("management_");
assertThat(properties.getUndertow().getAccesslog().getPrefix()).isEqualTo("management_");
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.web.server.jetty;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link JettyManagementServerProperties}.
*
* @author Andy Wilkinson
*/
class JettyManagementServerPropertiesTests {
@Test
void accessLogsArePrefixedByDefault() {
JettyManagementServerProperties properties = new JettyManagementServerProperties();
assertThat(properties.getAccesslog().getPrefix()).isEqualTo("management_");
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.web.server.tomcat;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link TomcatManagementServerProperties}.
*
* @author Andy Wilkinson
*/
class TomcatManagementServerPropertiesTests {
@Test
void accessLogsArePrefixedByDefault() {
TomcatManagementServerProperties properties = new TomcatManagementServerProperties();
assertThat(properties.getAccesslog().getPrefix()).isEqualTo("management_");
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.web.server.undertow;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link UndertowManagementServerProperties}.
*
* @author Andy Wilkinson
*/
class UndertowManagementServerPropertiesTests {
@Test
void accessLogsArePrefixedByDefault() {
UndertowManagementServerProperties properties = new UndertowManagementServerProperties();
assertThat(properties.getAccesslog().getPrefix()).isEqualTo("management_");
}
}