Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b603cd5d
Commit
b603cd5d
authored
May 21, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable Tomcat's MBean Registry by default
Closes gh-16498
parent
080a2f5c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
119 additions
and
16 deletions
+119
-16
ReactiveManagementChildContextConfiguration.java
...reactive/ReactiveManagementChildContextConfiguration.java
+2
-0
TomcatMetricsAutoConfigurationTests.java
...trics/web/tomcat/TomcatMetricsAutoConfigurationTests.java
+15
-0
BackgroundPreinitializer.java
...ramework/boot/autoconfigure/BackgroundPreinitializer.java
+0
-15
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+26
-0
ReactiveWebServerFactoryConfiguration.java
...e/web/reactive/ReactiveWebServerFactoryConfiguration.java
+7
-0
TomcatReactiveWebServerFactoryCustomizer.java
...eb/reactive/TomcatReactiveWebServerFactoryCustomizer.java
+48
-0
TomcatServletWebServerFactoryCustomizer.java
.../web/servlet/TomcatServletWebServerFactoryCustomizer.java
+5
-0
howto.adoc
...oot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
+14
-0
production-ready-features.adoc
...oot-docs/src/main/asciidoc/production-ready-features.adoc
+2
-1
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java
View file @
b603cd5d
...
...
@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.web.embedded.NettyWebServerFactory
import
org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer
;
import
org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer
;
import
org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryCustomizer
;
import
org.springframework.boot.autoconfigure.web.reactive.TomcatReactiveWebServerFactoryCustomizer
;
import
org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -65,6 +66,7 @@ public class ReactiveManagementChildContextConfiguration {
ReactiveManagementWebServerFactoryCustomizer
(
ListableBeanFactory
beanFactory
)
{
super
(
beanFactory
,
ReactiveWebServerFactoryCustomizer
.
class
,
TomcatWebServerFactoryCustomizer
.
class
,
TomcatReactiveWebServerFactoryCustomizer
.
class
,
JettyWebServerFactoryCustomizer
.
class
,
UndertowWebServerFactoryCustomizer
.
class
,
NettyWebServerFactoryCustomizer
.
class
);
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/tomcat/TomcatMetricsAutoConfigurationTests.java
View file @
b603cd5d
...
...
@@ -17,10 +17,12 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
.
tomcat
;
import
java.util.Collections
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.binder.tomcat.TomcatMetrics
;
import
io.micrometer.core.instrument.simple.SimpleMeterRegistry
;
import
org.apache.tomcat.util.modeler.Registry
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.SpringApplication
;
...
...
@@ -33,11 +35,13 @@ import org.springframework.boot.test.context.runner.ReactiveWebApplicationContex
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatWebServer
;
import
org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext
;
import
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -51,6 +55,7 @@ public class TomcatMetricsAutoConfigurationTests {
@Test
public
void
autoConfiguresTomcatMetricsWithEmbeddedServletTomcat
()
{
resetTomcatState
();
new
WebApplicationContextRunner
(
AnnotationConfigServletWebServerApplicationContext:
:
new
)
.
withConfiguration
(
AutoConfigurations
.
of
(
...
...
@@ -58,6 +63,7 @@ public class TomcatMetricsAutoConfigurationTests {
ServletWebServerFactoryAutoConfiguration
.
class
))
.
withUserConfiguration
(
ServletWebServerConfiguration
.
class
,
MeterRegistryConfiguration
.
class
)
.
withPropertyValues
(
"server.tomcat.mbeanregistry.enabled=true"
)
.
run
((
context
)
->
{
context
.
publishEvent
(
new
ApplicationStartedEvent
(
new
SpringApplication
(),
...
...
@@ -75,6 +81,7 @@ public class TomcatMetricsAutoConfigurationTests {
@Test
public
void
autoConfiguresTomcatMetricsWithEmbeddedReactiveTomcat
()
{
resetTomcatState
();
new
ReactiveWebApplicationContextRunner
(
AnnotationConfigReactiveWebServerApplicationContext:
:
new
)
.
withConfiguration
(
AutoConfigurations
.
of
(
...
...
@@ -82,6 +89,7 @@ public class TomcatMetricsAutoConfigurationTests {
ReactiveWebServerFactoryAutoConfiguration
.
class
))
.
withUserConfiguration
(
ReactiveWebServerConfiguration
.
class
,
MeterRegistryConfiguration
.
class
)
.
withPropertyValues
(
"server.tomcat.mbeanregistry.enabled=true"
)
.
run
((
context
)
->
{
context
.
publishEvent
(
new
ApplicationStartedEvent
(
new
SpringApplication
(),
...
...
@@ -130,6 +138,13 @@ public class TomcatMetricsAutoConfigurationTests {
.
hasBean
(
"customTomcatMetrics"
));
}
private
void
resetTomcatState
()
{
ReflectionTestUtils
.
setField
(
Registry
.
class
,
"registry"
,
null
);
AtomicInteger
containerCounter
=
(
AtomicInteger
)
ReflectionTestUtils
.
getField
(
TomcatWebServer
.
class
,
"containerCounter"
);
containerCounter
.
set
(-
1
);
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
MeterRegistryConfiguration
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java
View file @
b603cd5d
...
...
@@ -23,8 +23,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import
javax.validation.Configuration
;
import
javax.validation.Validation
;
import
org.apache.catalina.mbeans.MBeanFactory
;
import
org.springframework.boot.context.event.ApplicationFailedEvent
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.event.ApplicationStartingEvent
;
...
...
@@ -99,7 +97,6 @@ public class BackgroundPreinitializer
runSafely
(
new
ConversionServiceInitializer
());
runSafely
(
new
ValidationInitializer
());
runSafely
(
new
MessageConverterInitializer
());
runSafely
(
new
MBeanFactoryInitializer
());
runSafely
(
new
JacksonInitializer
());
runSafely
(
new
CharsetInitializer
());
preinitializationComplete
.
countDown
();
...
...
@@ -137,18 +134,6 @@ public class BackgroundPreinitializer
}
/**
* Early initializer to load Tomcat MBean XML.
*/
private
static
class
MBeanFactoryInitializer
implements
Runnable
{
@Override
public
void
run
()
{
new
MBeanFactory
();
}
}
/**
* Early initializer for javax.validation.
*/
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
b603cd5d
...
...
@@ -400,6 +400,11 @@ public class ServerProperties {
*/
private
final
Resource
resource
=
new
Resource
();
/**
* Modeler MBean Registry configuration.
*/
private
final
Mbeanregistry
mbeanregistry
=
new
Mbeanregistry
();
public
int
getMaxThreads
()
{
return
this
.
maxThreads
;
}
...
...
@@ -552,6 +557,10 @@ public class ServerProperties {
return
this
.
resource
;
}
public
Mbeanregistry
getMbeanregistry
()
{
return
this
.
mbeanregistry
;
}
/**
* Tomcat access log properties.
*/
...
...
@@ -821,6 +830,23 @@ public class ServerProperties {
}
public
static
class
Mbeanregistry
{
/**
* Whether Tomcat's MBean Registry should be enabled.
*/
private
boolean
enabled
;
public
boolean
isEnabled
()
{
return
this
.
enabled
;
}
public
void
setEnabled
(
boolean
enabled
)
{
this
.
enabled
=
enabled
;
}
}
}
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryConfiguration.java
View file @
b603cd5d
...
...
@@ -24,6 +24,7 @@ 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
;
...
...
@@ -98,6 +99,12 @@ abstract class ReactiveWebServerFactoryConfiguration {
return
factory
;
}
@Bean
public
TomcatReactiveWebServerFactoryCustomizer
tomcatReactiveWebServerFactoryCustomizer
(
ServerProperties
serverProperties
)
{
return
new
TomcatReactiveWebServerFactoryCustomizer
(
serverProperties
);
}
}
@Configuration
(
proxyBeanMethods
=
false
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/TomcatReactiveWebServerFactoryCustomizer.java
0 → 100644
View file @
b603cd5d
/*
* Copyright 2012-2019 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
.
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
;
/**
* {@link WebServerFactoryCustomizer} to apply {@link ServerProperties} to Tomcat reactive
* web servers.
*
* @author Andy Wilkinson
* @since 2.2.0
*/
public
class
TomcatReactiveWebServerFactoryCustomizer
implements
WebServerFactoryCustomizer
<
TomcatReactiveWebServerFactory
>
{
private
final
ServerProperties
serverProperties
;
public
TomcatReactiveWebServerFactoryCustomizer
(
ServerProperties
serverProperties
)
{
this
.
serverProperties
=
serverProperties
;
}
@Override
public
void
customize
(
TomcatReactiveWebServerFactory
factory
)
{
if
(!
this
.
serverProperties
.
getTomcat
().
getMbeanregistry
().
isEnabled
())
{
Registry
.
disableRegistry
();
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/TomcatServletWebServerFactoryCustomizer.java
View file @
b603cd5d
...
...
@@ -16,6 +16,8 @@
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
;
...
...
@@ -60,6 +62,9 @@ public class TomcatServletWebServerFactoryCustomizer
customizeUseRelativeRedirects
(
factory
,
tomcatProperties
.
getUseRelativeRedirects
());
}
if
(!
tomcatProperties
.
getMbeanregistry
().
isEnabled
())
{
Registry
.
disableRegistry
();
}
}
private
void
customizeRedirectContextRoot
(
ConfigurableTomcatWebServerFactory
factory
,
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
b603cd5d
...
...
@@ -1075,6 +1075,20 @@ include::{code-examples}/context/embedded/TomcatLegacyCookieProcessorExample.jav
[[howto-enable-tomcat-mbean-registry]]
=== Enable Tomcat's MBean Registry
Embedded Tomcat's MBean registry is disabled by default. This minimizes Tomcat's memory
footprint. If you want to use Tomcat's MBeans, for example so that they can be used to
expose metrics via Micrometer, you must use the `server.tomcat.mbeanregistry.enabled`
property to do so, as shown in the following example:
[source,properties,indent=0]
----
server.tomcat.mbeanregistry.enabled=true
----
[[howto-enable-multiple-listeners-in-undertow]]
=== Enable Multiple Listeners with Undertow
Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc
View file @
b603cd5d
...
...
@@ -1793,7 +1793,8 @@ Spring Boot registers the following core metrics when applicable:
* Logback metrics: record the number of events logged to Logback at each level
* Uptime metrics: report a gauge for uptime and a fixed gauge representing the
application's absolute start time
* Tomcat metrics
* Tomcat metrics (`server.tomcat.mbeanregistry.enabled` must be set to `true` for all
Tomcat metrics to be registered)
* https://docs.spring.io/spring-integration/docs/current/reference/html/system-management-chapter.html#micrometer-integration[Spring Integration] metrics
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment