Skip to content

Commit 2744973

Browse files
committed
Pull up setDisableMBeanRegistry
Issue: 44070
1 parent cd758cd commit 2744973

File tree

7 files changed

+20
-51
lines changed

7 files changed

+20
-51
lines changed

spring-boot-project/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/ConfigurableTomcatWebServerFactory.java

+7
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,11 @@ public interface ConfigurableTomcatWebServerFactory extends ConfigurableWebServe
9191
*/
9292
void setUseApr(boolean useApr);
9393

94+
/**
95+
* Set whether the factory should disable Tomcat's MBean registry prior to creating
96+
* the server.
97+
* @param disableMBeanRegistry whether to disable the MBean registry
98+
*/
99+
void setDisableMBeanRegistry(boolean disableMBeanRegistry);
100+
94101
}

spring-boot-project/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/TomcatWebServerFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public boolean isDisableMBeanRegistry() {
351351
* the server.
352352
* @param disableMBeanRegistry whether to disable the MBean registry
353353
*/
354+
@Override
354355
public void setDisableMBeanRegistry(boolean disableMBeanRegistry) {
355356
this.disableMBeanRegistry = disableMBeanRegistry;
356357
}

spring-boot-project/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerFactoryCustomizer.java

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
152152
.as(this::joinCharacters)
153153
.whenHasText()
154154
.to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
155+
map.from(this.tomcatProperties.getMbeanregistry()::isEnabled)
156+
.as((enable) -> !enable)
157+
.to(factory::setDisableMBeanRegistry);
155158
customizeStaticResources(factory);
156159
customizeErrorReportValve(this.serverProperties.getError(), factory);
157160
factory.setUseApr(getUseApr(this.tomcatProperties.getUseApr()));

spring-boot-project/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/reactive/autoconfigure/TomcatReactiveWebServerAutoConfiguration.java

-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@
5151
@Import({ TomcatWebServerConfiguration.class, ReactiveWebServerConfiguration.class })
5252
public class TomcatReactiveWebServerAutoConfiguration {
5353

54-
@Bean
55-
TomcatReactiveWebServerFactoryCustomizer tomcatReactiveWebServerFactoryCustomizer(
56-
TomcatServerProperties tomcatProperties) {
57-
return new TomcatReactiveWebServerFactoryCustomizer(tomcatProperties);
58-
}
59-
6054
@Bean
6155
@ConditionalOnMissingBean(ReactiveWebServerFactory.class)
6256
TomcatReactiveWebServerFactory tomcatReactiveWebServerFactory(

spring-boot-project/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/reactive/autoconfigure/TomcatReactiveWebServerFactoryCustomizer.java

-44
This file was deleted.

spring-boot-project/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/servlet/autoconfigure/TomcatServletWebServerFactoryCustomizer.java

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public void customize(TomcatServletWebServerFactory factory) {
5353
customizeRedirectContextRoot(factory, this.tomcatProperties.getRedirectContextRoot());
5454
}
5555
customizeUseRelativeRedirects(factory, this.tomcatProperties.isUseRelativeRedirects());
56-
factory.setDisableMBeanRegistry(!this.tomcatProperties.getMbeanregistry().isEnabled());
5756
}
5857

5958
private void customizeRedirectContextRoot(ConfigurableTomcatWebServerFactory factory, boolean redirectContextRoot) {

spring-boot-project/spring-boot-tomcat/src/test/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerFactoryCustomizerTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,15 @@ void configureExecutor() {
585585
});
586586
}
587587

588+
@Test
589+
void enableMBeanRegistry() {
590+
bind("server.tomcat.mbeanregistry.enabled=true");
591+
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
592+
assertThat(factory.isDisableMBeanRegistry()).isTrue();
593+
this.customizer.customize(factory);
594+
assertThat(factory.isDisableMBeanRegistry()).isFalse();
595+
}
596+
588597
private void bind(String... inlinedProperties) {
589598
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, inlinedProperties);
590599
Binder binder = new Binder(ConfigurationPropertySources.get(this.environment));

0 commit comments

Comments
 (0)