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
0df4156b
Commit
0df4156b
authored
Sep 24, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lazy initialization of management server properties
parent
5b1503d0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
12 deletions
+40
-12
EndpointWebMvcAutoConfiguration.java
...ctuate/autoconfigure/EndpointWebMvcAutoConfiguration.java
+9
-3
EndpointWebMvcChildContextConfiguration.java
...utoconfigure/EndpointWebMvcChildContextConfiguration.java
+25
-9
DispatcherServletAutoConfiguration.java
...autoconfigure/web/DispatcherServletAutoConfiguration.java
+2
-0
EmbeddedServletContainerAutoConfiguration.java
...figure/web/EmbeddedServletContainerAutoConfiguration.java
+2
-0
WebMvcAutoConfiguration.java
...ework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+2
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java
View file @
0df4156b
...
...
@@ -26,7 +26,6 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
...
...
@@ -38,6 +37,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
;
import
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
;
...
...
@@ -50,6 +50,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.web.context.support.GenericWebApplicationContext
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.servlet.DispatcherServlet
;
...
...
@@ -133,7 +134,8 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
// is intentionally not completely auto-configured.
childContext
.
register
(
EndpointWebMvcChildContextConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
EmbeddedServletContainerAutoConfiguration
.
class
);
EmbeddedServletContainerAutoConfiguration
.
class
,
DispatcherServletAutoConfiguration
.
class
);
// Ensure close on the parent also closes the child
if
(
this
.
applicationContext
instanceof
ConfigurableApplicationContext
)
{
...
...
@@ -154,7 +156,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
DISABLE
,
SAME
,
DIFFERENT
;
public
static
ManagementServerPort
get
(
BeanFactory
beanFactory
)
{
public
static
ManagementServerPort
get
(
ApplicationContext
beanFactory
)
{
ServerProperties
serverProperties
;
try
{
...
...
@@ -176,6 +178,10 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
if
(
DISABLED_PORT
.
equals
(
managementServerProperties
.
getPort
()))
{
return
DISABLE
;
}
if
(!(
beanFactory
instanceof
GenericWebApplicationContext
))
{
// Current context is no a a webapp
return
DIFFERENT
;
}
return
managementServerProperties
.
getPort
()
==
null
||
serverProperties
.
getPort
()
==
managementServerProperties
.
getPort
()
?
SAME
:
DIFFERENT
;
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java
View file @
0df4156b
...
...
@@ -19,7 +19,9 @@ package org.springframework.boot.actuate.autoconfigure;
import
javax.servlet.Filter
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.beans.factory.HierarchicalBeanFactory
;
import
org.springframework.beans.factory.ListableBeanFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter
;
import
org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping
;
...
...
@@ -44,17 +46,31 @@ import org.springframework.web.servlet.HandlerMapping;
* @see EndpointWebMvcAutoConfiguration
*/
@Configuration
public
class
EndpointWebMvcChildContextConfiguration
implements
EmbeddedServletContainerCustomizer
{
public
class
EndpointWebMvcChildContextConfiguration
{
@Autowired
private
ManagementServerProperties
managementServerProperties
;
@Configuration
protected
static
class
ServerCustomization
implements
EmbeddedServletContainerCustomizer
{
@Autowired
private
ListableBeanFactory
beanFactory
;
// This needs to be lazily initialized because EmbeddedServletContainerCustomizer
// instances get their callback very early in the context lifecycle.
private
ManagementServerProperties
managementServerProperties
;
@Override
public
void
customize
(
ConfigurableEmbeddedServletContainerFactory
factory
)
{
if
(
this
.
managementServerProperties
==
null
)
{
this
.
managementServerProperties
=
BeanFactoryUtils
.
beanOfTypeIncludingAncestors
(
this
.
beanFactory
,
ManagementServerProperties
.
class
);
}
factory
.
setPort
(
this
.
managementServerProperties
.
getPort
());
factory
.
setAddress
(
this
.
managementServerProperties
.
getAddress
());
factory
.
setContextPath
(
this
.
managementServerProperties
.
getContextPath
());
}
@Override
public
void
customize
(
ConfigurableEmbeddedServletContainerFactory
factory
)
{
factory
.
setPort
(
this
.
managementServerProperties
.
getPort
());
factory
.
setAddress
(
this
.
managementServerProperties
.
getAddress
());
factory
.
setContextPath
(
this
.
managementServerProperties
.
getContextPath
());
}
@Bean
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java
View file @
0df4156b
...
...
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ConditionContext
;
...
...
@@ -41,6 +42,7 @@ import org.springframework.web.servlet.DispatcherServlet;
*/
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass
(
DispatcherServlet
.
class
)
@AutoConfigureAfter
(
EmbeddedServletContainerAutoConfiguration
.
class
)
public
class
DispatcherServletAutoConfiguration
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration.java
View file @
0df4156b
...
...
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.SearchStrategy
;
import
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration.EmbeddedServletContainerCustomizerBeanPostProcessorRegistrar
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor
;
...
...
@@ -53,6 +54,7 @@ import org.springframework.core.type.AnnotationMetadata;
*/
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@Configuration
@ConditionalOnWebApplication
@Import
(
EmbeddedServletContainerCustomizerBeanPostProcessorRegistrar
.
class
)
public
class
EmbeddedServletContainerAutoConfiguration
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
View file @
0df4156b
...
...
@@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
...
...
@@ -67,6 +68,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
* @author Dave Syer
*/
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass
({
Servlet
.
class
,
DispatcherServlet
.
class
,
WebMvcConfigurerAdapter
.
class
})
@ConditionalOnMissingBean
(
WebMvcConfigurationSupport
.
class
)
...
...
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