Pull up setDisableMBeanRegistry

Issue: 44070
This commit is contained in:
Andy Wilkinson 2025-03-18 19:39:45 +00:00 committed by Phillip Webb
parent df81e9ccfa
commit d53704f942
7 changed files with 20 additions and 51 deletions

View File

@ -91,4 +91,11 @@ public interface ConfigurableTomcatWebServerFactory extends ConfigurableWebServe
*/
void setUseApr(boolean useApr);
/**
* Set whether the factory should disable Tomcat's MBean registry prior to creating
* the server.
* @param disableMBeanRegistry whether to disable the MBean registry
*/
void setDisableMBeanRegistry(boolean disableMBeanRegistry);
}

View File

@ -351,6 +351,7 @@ public class TomcatWebServerFactory extends AbstractConfigurableWebServerFactory
* the server.
* @param disableMBeanRegistry whether to disable the MBean registry
*/
@Override
public void setDisableMBeanRegistry(boolean disableMBeanRegistry) {
this.disableMBeanRegistry = disableMBeanRegistry;
}

View File

@ -152,6 +152,9 @@ public class TomcatWebServerFactoryCustomizer
.as(this::joinCharacters)
.whenHasText()
.to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
map.from(this.tomcatProperties.getMbeanregistry()::isEnabled)
.as((enable) -> !enable)
.to(factory::setDisableMBeanRegistry);
customizeStaticResources(factory);
customizeErrorReportValve(this.serverProperties.getError(), factory);
factory.setUseApr(getUseApr(this.tomcatProperties.getUseApr()));

View File

@ -51,12 +51,6 @@ import org.springframework.http.ReactiveHttpInputMessage;
@Import({ TomcatWebServerConfiguration.class, ReactiveWebServerConfiguration.class })
public class TomcatReactiveWebServerAutoConfiguration {
@Bean
TomcatReactiveWebServerFactoryCustomizer tomcatReactiveWebServerFactoryCustomizer(
TomcatServerProperties tomcatProperties) {
return new TomcatReactiveWebServerFactoryCustomizer(tomcatProperties);
}
@Bean
@ConditionalOnMissingBean(ReactiveWebServerFactory.class)
TomcatReactiveWebServerFactory tomcatReactiveWebServerFactory(

View File

@ -1,44 +0,0 @@
/*
* 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.tomcat.autoconfigure.reactive;
import org.springframework.boot.tomcat.autoconfigure.TomcatServerProperties;
import org.springframework.boot.tomcat.reactive.TomcatReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
/**
* {@link WebServerFactoryCustomizer} to apply {@link TomcatServerProperties} to Tomcat
* reactive web servers.
*
* @author Andy Wilkinson
* @since 4.0.0
*/
public class TomcatReactiveWebServerFactoryCustomizer
implements WebServerFactoryCustomizer<TomcatReactiveWebServerFactory> {
private final TomcatServerProperties tomcatProperties;
public TomcatReactiveWebServerFactoryCustomizer(TomcatServerProperties tomcatProperties) {
this.tomcatProperties = tomcatProperties;
}
@Override
public void customize(TomcatReactiveWebServerFactory factory) {
factory.setDisableMBeanRegistry(!this.tomcatProperties.getMbeanregistry().isEnabled());
}
}

View File

@ -53,7 +53,6 @@ class TomcatServletWebServerFactoryCustomizer
customizeRedirectContextRoot(factory, this.tomcatProperties.getRedirectContextRoot());
}
customizeUseRelativeRedirects(factory, this.tomcatProperties.isUseRelativeRedirects());
factory.setDisableMBeanRegistry(!this.tomcatProperties.getMbeanregistry().isEnabled());
}
private void customizeRedirectContextRoot(ConfigurableTomcatWebServerFactory factory, boolean redirectContextRoot) {

View File

@ -588,6 +588,15 @@ class TomcatWebServerFactoryCustomizerTests {
});
}
@Test
void enableMBeanRegistry() {
bind("server.tomcat.mbeanregistry.enabled=true");
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
assertThat(factory.isDisableMBeanRegistry()).isTrue();
this.customizer.customize(factory);
assertThat(factory.isDisableMBeanRegistry()).isFalse();
}
private void bind(String... inlinedProperties) {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, inlinedProperties);
Binder binder = new Binder(ConfigurationPropertySources.get(this.environment));