Defer disabling registry until Tomcat server is being created

Closes gh-16498
pull/17002/head
Andy Wilkinson 6 years ago
parent 6787b918d5
commit 0eb6c0ddd3

@ -65,6 +65,14 @@ public class ReactiveWebServerFactoryAutoConfiguration {
return new ReactiveWebServerFactoryCustomizer(serverProperties);
}
@Bean
@ConditionalOnClass(name = "org.apache.catalina.startup.Tomcat")
public TomcatReactiveWebServerFactoryCustomizer tomcatReactiveWebServerFactoryCustomizer(
ServerProperties serverProperties) {
return new TomcatReactiveWebServerFactoryCustomizer(serverProperties);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "server.forward-headers-strategy",

@ -24,7 +24,6 @@ import reactor.netty.http.server.HttpServer;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory;
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
@ -99,12 +98,6 @@ abstract class ReactiveWebServerFactoryConfiguration {
return factory;
}
@Bean
public TomcatReactiveWebServerFactoryCustomizer tomcatReactiveWebServerFactoryCustomizer(
ServerProperties serverProperties) {
return new TomcatReactiveWebServerFactoryCustomizer(serverProperties);
}
}
@Configuration(proxyBeanMethods = false)

@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.web.reactive;
import org.apache.tomcat.util.modeler.Registry;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
@ -40,9 +38,8 @@ public class TomcatReactiveWebServerFactoryCustomizer
@Override
public void customize(TomcatReactiveWebServerFactory factory) {
if (!this.serverProperties.getTomcat().getMbeanregistry().isEnabled()) {
Registry.disableRegistry();
}
factory.setDisableMBeanRegistry(
!this.serverProperties.getTomcat().getMbeanregistry().isEnabled());
}
}

@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.web.servlet;
import org.apache.tomcat.util.modeler.Registry;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
@ -62,9 +60,7 @@ public class TomcatServletWebServerFactoryCustomizer
customizeUseRelativeRedirects(factory,
tomcatProperties.getUseRelativeRedirects());
}
if (!tomcatProperties.getMbeanregistry().isEnabled()) {
Registry.disableRegistry();
}
factory.setDisableMBeanRegistry(!tomcatProperties.getMbeanregistry().isEnabled());
}
private void customizeRedirectContextRoot(ConfigurableTomcatWebServerFactory factory,

@ -36,6 +36,7 @@ import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http2.Http2Protocol;
import org.apache.tomcat.util.modeler.Registry;
import org.apache.tomcat.util.scan.StandardJarScanFilter;
import org.springframework.boot.util.LambdaSafe;
@ -82,6 +83,8 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
private int backgroundProcessorDelay;
private boolean disableMBeanRegistry = true;
/**
* Create a new {@link TomcatServletWebServerFactory} instance.
*/
@ -106,6 +109,9 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
@Override
public WebServer getWebServer(HttpHandler httpHandler) {
if (this.disableMBeanRegistry) {
Registry.disableRegistry();
}
Tomcat tomcat = new Tomcat();
File baseDir = (this.baseDirectory != null) ? this.baseDirectory
: createTempDir("tomcat");
@ -413,4 +419,14 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
this.protocol = protocol;
}
/**
* Set whether the factory should disable Tomcat's MBean registry prior to creating
* the server.
* @param disableMBeanRegistry whether to disable the MBean registry
* @since 2.2.0
*/
public void setDisableMBeanRegistry(boolean disableMBeanRegistry) {
this.disableMBeanRegistry = disableMBeanRegistry;
}
}

@ -60,6 +60,7 @@ import org.apache.catalina.webresources.StandardRoot;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http2.Http2Protocol;
import org.apache.tomcat.util.modeler.Registry;
import org.apache.tomcat.util.scan.StandardJarScanFilter;
import org.springframework.boot.util.LambdaSafe;
@ -133,6 +134,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
private int backgroundProcessorDelay;
private boolean disableMBeanRegistry = true;
/**
* Create a new {@link TomcatServletWebServerFactory} instance.
*/
@ -167,6 +170,9 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
if (this.disableMBeanRegistry) {
Registry.disableRegistry();
}
Tomcat tomcat = new Tomcat();
File baseDir = (this.baseDirectory != null) ? this.baseDirectory
: createTempDir("tomcat");
@ -707,6 +713,16 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
this.backgroundProcessorDelay = delay;
}
/**
* Set whether the factory should disable Tomcat's MBean registry prior to creating
* the server.
* @param disableMBeanRegistry whether to disable the MBean registry
* @since 2.2.0
*/
public void setDisableMBeanRegistry(boolean disableMBeanRegistry) {
this.disableMBeanRegistry = disableMBeanRegistry;
}
/**
* {@link LifecycleListener} to disable persistence in the {@link StandardManager}. A
* {@link LifecycleListener} is used so not to interfere with Tomcat's default manager

Loading…
Cancel
Save