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
c0a91478
Commit
c0a91478
authored
Apr 02, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only start management server once main server is initialized
Closes gh-15378
parent
7175b806
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
39 deletions
+23
-39
ManagementContextAutoConfiguration.java
...figure/web/server/ManagementContextAutoConfiguration.java
+5
-18
ManagementContextAutoConfigurationTests.java
...e/web/server/ManagementContextAutoConfigurationTests.java
+18
-21
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration.java
View file @
c0a91478
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,9 +16,6 @@
...
@@ -16,9 +16,6 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
web
.
server
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
web
.
server
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.SmartInitializingSingleton
;
import
org.springframework.beans.factory.SmartInitializingSingleton
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextFactory
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextFactory
;
...
@@ -29,7 +26,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
...
@@ -29,7 +26,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
import
org.springframework.boot.context.event.ApplicationFailedEvent
;
import
org.springframework.boot.context.event.ApplicationFailedEvent
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.context.ConfigurableWebServerApplicationContext
;
import
org.springframework.boot.web.context.ConfigurableWebServerApplicationContext
;
import
org.springframework.boot.web.context.WebServer
ApplicationContex
t
;
import
org.springframework.boot.web.context.WebServer
InitializedEven
t
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
...
@@ -59,9 +56,6 @@ import org.springframework.util.Assert;
...
@@ -59,9 +56,6 @@ import org.springframework.util.Assert;
ManagementServerProperties
.
class
})
ManagementServerProperties
.
class
})
public
class
ManagementContextAutoConfiguration
{
public
class
ManagementContextAutoConfiguration
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
ManagementContextAutoConfiguration
.
class
);
@Configuration
@Configuration
@ConditionalOnManagementPort
(
ManagementPortType
.
SAME
)
@ConditionalOnManagementPort
(
ManagementPortType
.
SAME
)
static
class
SameManagementContextConfiguration
static
class
SameManagementContextConfiguration
...
@@ -122,7 +116,7 @@ public class ManagementContextAutoConfiguration {
...
@@ -122,7 +116,7 @@ public class ManagementContextAutoConfiguration {
@Configuration
@Configuration
@ConditionalOnManagementPort
(
ManagementPortType
.
DIFFERENT
)
@ConditionalOnManagementPort
(
ManagementPortType
.
DIFFERENT
)
static
class
DifferentManagementContextConfiguration
static
class
DifferentManagementContextConfiguration
implements
SmartInitializingSingleton
{
implements
ApplicationListener
<
WebServerInitializedEvent
>
{
private
final
ApplicationContext
applicationContext
;
private
final
ApplicationContext
applicationContext
;
...
@@ -135,10 +129,8 @@ public class ManagementContextAutoConfiguration {
...
@@ -135,10 +129,8 @@ public class ManagementContextAutoConfiguration {
}
}
@Override
@Override
public
void
afterSingletonsInstantiated
()
{
public
void
onApplicationEvent
(
WebServerInitializedEvent
event
)
{
if
(
this
.
applicationContext
instanceof
WebServerApplicationContext
if
(
event
.
getApplicationContext
().
equals
(
this
.
applicationContext
))
{
&&
((
WebServerApplicationContext
)
this
.
applicationContext
)
.
getWebServer
()
!=
null
)
{
ConfigurableWebServerApplicationContext
managementContext
=
this
.
managementContextFactory
ConfigurableWebServerApplicationContext
managementContext
=
this
.
managementContextFactory
.
createManagementContext
(
this
.
applicationContext
,
.
createManagementContext
(
this
.
applicationContext
,
EnableChildManagementContextConfiguration
.
class
,
EnableChildManagementContextConfiguration
.
class
,
...
@@ -150,11 +142,6 @@ public class ManagementContextAutoConfiguration {
...
@@ -150,11 +142,6 @@ public class ManagementContextAutoConfiguration {
managementContext
);
managementContext
);
managementContext
.
refresh
();
managementContext
.
refresh
();
}
}
else
{
logger
.
warn
(
"Could not start embedded management container on "
+
"different port (management endpoints are still available "
+
"through JMX)"
);
}
}
}
private
void
setClassLoaderIfPossible
(
ConfigurableApplicationContext
child
)
{
private
void
setClassLoaderIfPossible
(
ConfigurableApplicationContext
child
)
{
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfigurationTests.java
View file @
c0a91478
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -15,6 +15,9 @@
...
@@ -15,6 +15,9 @@
*/
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
web
.
server
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
web
.
server
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -33,28 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -33,28 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ManagementContextAutoConfiguration}.
* Tests for {@link ManagementContextAutoConfiguration}.
*
*
* @author Madhura Bhave
* @author Madhura Bhave
* @author Andy Wilkinson
*/
*/
public
class
ManagementContextAutoConfigurationTests
{
public
class
ManagementContextAutoConfigurationTests
{
private
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
ManagementContextAutoConfiguration
.
class
,
ServletManagementContextAutoConfiguration
.
class
));
@Rule
@Rule
public
OutputCapture
output
=
new
OutputCapture
();
public
OutputCapture
output
=
new
OutputCapture
();
@Test
public
void
managementServerPortShouldBeIgnoredForNonEmbeddedServer
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.server.port=8081"
)
.
run
((
context
)
->
{
assertThat
(
context
.
getStartupFailure
()).
isNull
();
assertThat
(
this
.
output
.
toString
())
.
contains
(
"Could not start embedded management container on "
+
"different port (management endpoints are still available through JMX)"
);
});
}
@Test
@Test
public
void
childManagementContextShouldStartForEmbeddedServer
()
{
public
void
childManagementContextShouldStartForEmbeddedServer
()
{
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
(
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
(
...
@@ -65,10 +53,19 @@ public class ManagementContextAutoConfigurationTests {
...
@@ -65,10 +53,19 @@ public class ManagementContextAutoConfigurationTests {
ServletManagementContextAutoConfiguration
.
class
,
ServletManagementContextAutoConfiguration
.
class
,
WebEndpointAutoConfiguration
.
class
,
WebEndpointAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
));
EndpointAutoConfiguration
.
class
));
contextRunner
.
withPropertyValues
(
"management.server.port=8081"
)
contextRunner
.
withPropertyValues
(
"server.port=0"
,
"management.server.port=0"
).
run
(
.
run
((
context
)
->
assertThat
(
this
.
output
.
toString
()).
doesNotContain
(
(
context
)
->
assertThat
(
tomcatStartedOccurencesIn
(
this
.
output
.
toString
()))
"Could not start embedded management container on "
.
isEqualTo
(
2
));
+
"different port (management endpoints are still available through JMX)"
));
}
private
int
tomcatStartedOccurencesIn
(
String
output
)
{
int
matches
=
0
;
Matcher
matcher
=
Pattern
.
compile
(
"Tomcat started on port"
).
matcher
(
output
);
while
(
matcher
.
find
())
{
matches
++;
}
return
matches
;
}
}
}
}
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