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
55a84c7b
Commit
55a84c7b
authored
Sep 24, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.1.x'
parents
b4c94f42
23ff7c91
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
20 deletions
+66
-20
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+12
-10
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+46
-10
RandomValuePropertySource.java
...mework/boot/context/config/RandomValuePropertySource.java
+8
-0
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
55a84c7b
...
@@ -1001,26 +1001,28 @@ You can also use regular Spring MVC features like http://docs.spring.io/spring/d
...
@@ -1001,26 +1001,28 @@ You can also use regular Spring MVC features like http://docs.spring.io/spring/d
methods] and http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice[`@ControllerAdvice`].
methods] and http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice[`@ControllerAdvice`].
The `ErrorController` will then pick up any unhandled exceptions.
The `ErrorController` will then pick up any unhandled exceptions.
N.B. if you register an `ErrorPage` with a path that will end up being handled by a `Filter` (e.g. as is common with some non-Spring web frameworks,
N.B. if you register an `ErrorPage` with a path that will end up being handled by a
like Jersey and Wicket), then the `Filter` has to be explicitly registered as an `ERROR` dispatcher, e.g.
`Filter` (e.g. as is common with some non-Spring web frameworks, like Jersey and Wicket),
then the `Filter` has to be explicitly registered as an `ERROR` dispatcher, e.g.
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
----
@Bean
@Bean
public FilterRegistrationBean myFilter() {
public FilterRegistrationBean myFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new MyFilter());
registration.setFilter(new MyFilter());
...
...
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
return registration;
return registration;
}
}
----
----
(the default `FilterRegistrationBean` does not include the `ERROR` dispatcher type).
(the default `FilterRegistrationBean` does not include the `ERROR` dispatcher type).
[[boot-features-embedded-container]]
[[boot-features-embedded-container]]
=== Embedded servlet container support
=== Embedded servlet container support
Spring Boot includes support for embedded Tomcat and Jetty servers. Most developers will
Spring Boot includes support for embedded Tomcat and Jetty servers. Most developers will
...
...
spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
55a84c7b
...
@@ -27,6 +27,8 @@ import java.util.List;
...
@@ -27,6 +27,8 @@ import java.util.List;
import
java.util.Queue
;
import
java.util.Queue
;
import
java.util.Set
;
import
java.util.Set
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
...
@@ -106,6 +108,8 @@ public class ConfigFileApplicationListener implements
...
@@ -106,6 +108,8 @@ public class ConfigFileApplicationListener implements
public
static
final
int
DEFAULT_ORDER
=
Ordered
.
HIGHEST_PRECEDENCE
+
10
;
public
static
final
int
DEFAULT_ORDER
=
Ordered
.
HIGHEST_PRECEDENCE
+
10
;
private
static
Log
logger
=
LogFactory
.
getLog
(
ConfigFileApplicationListener
.
class
);
private
String
searchLocations
;
private
String
searchLocations
;
private
String
names
;
private
String
names
;
...
@@ -114,6 +118,8 @@ public class ConfigFileApplicationListener implements
...
@@ -114,6 +118,8 @@ public class ConfigFileApplicationListener implements
private
final
ConversionService
conversionService
=
new
DefaultConversionService
();
private
final
ConversionService
conversionService
=
new
DefaultConversionService
();
private
final
List
<
Object
>
debug
=
new
ArrayList
<
Object
>();
@Override
@Override
public
void
onApplicationEvent
(
ApplicationEvent
event
)
{
public
void
onApplicationEvent
(
ApplicationEvent
event
)
{
if
(
event
instanceof
ApplicationEnvironmentPreparedEvent
)
{
if
(
event
instanceof
ApplicationEnvironmentPreparedEvent
)
{
...
@@ -140,9 +146,21 @@ public class ConfigFileApplicationListener implements
...
@@ -140,9 +146,21 @@ public class ConfigFileApplicationListener implements
}
}
private
void
onApplicationPreparedEvent
(
ApplicationPreparedEvent
event
)
{
private
void
onApplicationPreparedEvent
(
ApplicationPreparedEvent
event
)
{
logDebugMessages
();
addPostProcessors
(
event
.
getApplicationContext
());
addPostProcessors
(
event
.
getApplicationContext
());
}
}
private
void
logDebugMessages
()
{
// Debug logging is deferred because the Logging initialization might not have
// run at the time that config file decisions are taken
if
(
logger
.
isDebugEnabled
())
{
for
(
Object
message
:
this
.
debug
)
{
logger
.
debug
(
message
);
}
}
this
.
debug
.
clear
();
}
/**
/**
* Add config file property sources to the specified environment.
* Add config file property sources to the specified environment.
* @param environment the environment to add source to
* @param environment the environment to add source to
...
@@ -270,6 +288,8 @@ public class ConfigFileApplicationListener implements
...
@@ -270,6 +288,8 @@ public class ConfigFileApplicationListener implements
private
boolean
activatedProfiles
;
private
boolean
activatedProfiles
;
private
final
List
<
Object
>
debug
=
ConfigFileApplicationListener
.
this
.
debug
;
public
Loader
(
ConfigurableEnvironment
environment
,
ResourceLoader
resourceLoader
)
{
public
Loader
(
ConfigurableEnvironment
environment
,
ResourceLoader
resourceLoader
)
{
this
.
environment
=
environment
;
this
.
environment
=
environment
;
this
.
resourceLoader
=
resourceLoader
==
null
?
new
DefaultResourceLoader
()
this
.
resourceLoader
=
resourceLoader
==
null
?
new
DefaultResourceLoader
()
...
@@ -280,7 +300,6 @@ public class ConfigFileApplicationListener implements
...
@@ -280,7 +300,6 @@ public class ConfigFileApplicationListener implements
this
.
propertiesLoader
=
new
PropertySourcesLoader
();
this
.
propertiesLoader
=
new
PropertySourcesLoader
();
this
.
profiles
=
Collections
.
asLifoQueue
(
new
LinkedList
<
String
>());
this
.
profiles
=
Collections
.
asLifoQueue
(
new
LinkedList
<
String
>());
this
.
activatedProfiles
=
false
;
this
.
activatedProfiles
=
false
;
if
(
this
.
environment
.
containsProperty
(
ACTIVE_PROFILES_PROPERTY
))
{
if
(
this
.
environment
.
containsProperty
(
ACTIVE_PROFILES_PROPERTY
))
{
// Any pre-existing active profiles set via property sources (e.g. System
// Any pre-existing active profiles set via property sources (e.g. System
// properties) take precedence over those added in config files.
// properties) take precedence over those added in config files.
...
@@ -354,29 +373,46 @@ public class ConfigFileApplicationListener implements
...
@@ -354,29 +373,46 @@ public class ConfigFileApplicationListener implements
private
PropertySource
<?>
loadIntoGroup
(
String
identifier
,
String
location
,
private
PropertySource
<?>
loadIntoGroup
(
String
identifier
,
String
location
,
String
profile
)
throws
IOException
{
String
profile
)
throws
IOException
{
Resource
resource
=
this
.
resourceLoader
.
getResource
(
location
);
Resource
resource
=
this
.
resourceLoader
.
getResource
(
location
);
PropertySource
<?>
propertySource
=
null
;
if
(
resource
!=
null
)
{
if
(
resource
!=
null
)
{
String
name
=
"applicationConfig: ["
+
location
+
"]"
;
String
name
=
"applicationConfig: ["
+
location
+
"]"
;
String
group
=
"applicationConfig: ["
+
identifier
+
"]"
;
String
group
=
"applicationConfig: ["
+
identifier
+
"]"
;
PropertySource
<?>
propertySource
=
this
.
propertiesLoader
.
load
(
resourc
e
,
propertySource
=
this
.
propertiesLoader
.
load
(
resource
,
group
,
nam
e
,
group
,
name
,
profile
);
profile
);
if
(
propertySource
!=
null
)
{
if
(
propertySource
!=
null
)
{
maybeActivateProfiles
(
propertySource
maybeActivateProfiles
(
propertySource
.
getProperty
(
ACTIVE_PROFILES_PROPERTY
));
.
getProperty
(
ACTIVE_PROFILES_PROPERTY
));
addIncludeProfiles
(
propertySource
addIncludeProfiles
(
propertySource
.
getProperty
(
INCLUDE_PROFILES_PROPERTY
));
.
getProperty
(
INCLUDE_PROFILES_PROPERTY
));
}
}
return
propertySource
;
}
}
return
null
;
StringBuilder
msg
=
new
StringBuilder
();
msg
.
append
(
propertySource
==
null
?
"Skipped "
:
"Loaded "
);
msg
.
append
(
"config file "
);
msg
.
append
(
"'"
+
location
+
"' "
);
msg
.
append
(
StringUtils
.
hasLength
(
profile
)
?
"for profile "
:
""
);
msg
.
append
(
resource
==
null
||
!
resource
.
exists
()
?
"resource not found"
:
""
);
this
.
debug
.
add
(
msg
);
return
propertySource
;
}
}
private
void
maybeActivateProfiles
(
Object
value
)
{
private
void
maybeActivateProfiles
(
Object
value
)
{
if
(!
this
.
activatedProfiles
==
true
)
{
if
(
this
.
activatedProfiles
)
{
Set
<
String
>
profiles
=
getProfilesForValue
(
value
);
if
(
value
!=
null
)
{
activateProfiles
(
profiles
);
this
.
debug
.
add
(
"Profiles already activated, '"
+
value
if
(
profiles
.
size
()
>
0
)
{
+
"' will not be applied"
);
this
.
activatedProfiles
=
true
;
}
}
return
;
}
Set
<
String
>
profiles
=
getProfilesForValue
(
value
);
activateProfiles
(
profiles
);
if
(
profiles
.
size
()
>
0
)
{
this
.
debug
.
add
(
"Activated profiles "
+
StringUtils
.
collectionToCommaDelimitedString
(
profiles
));
this
.
activatedProfiles
=
true
;
}
}
}
}
...
...
spring-boot/src/main/java/org/springframework/boot/context/config/RandomValuePropertySource.java
View file @
55a84c7b
...
@@ -18,6 +18,8 @@ package org.springframework.boot.context.config;
...
@@ -18,6 +18,8 @@ package org.springframework.boot.context.config;
import
java.util.Random
;
import
java.util.Random
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
...
@@ -33,6 +35,8 @@ import org.springframework.util.StringUtils;
...
@@ -33,6 +35,8 @@ import org.springframework.util.StringUtils;
*/
*/
public
class
RandomValuePropertySource
extends
PropertySource
<
Random
>
{
public
class
RandomValuePropertySource
extends
PropertySource
<
Random
>
{
private
static
Log
logger
=
LogFactory
.
getLog
(
RandomValuePropertySource
.
class
);
public
RandomValuePropertySource
(
String
name
)
{
public
RandomValuePropertySource
(
String
name
)
{
super
(
name
,
new
Random
());
super
(
name
,
new
Random
());
}
}
...
@@ -42,6 +46,9 @@ public class RandomValuePropertySource extends PropertySource<Random> {
...
@@ -42,6 +46,9 @@ public class RandomValuePropertySource extends PropertySource<Random> {
if
(!
name
.
startsWith
(
"random."
))
{
if
(!
name
.
startsWith
(
"random."
))
{
return
null
;
return
null
;
}
}
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Generating random property for '"
+
name
+
"'"
);
}
if
(
name
.
endsWith
(
"int"
))
{
if
(
name
.
endsWith
(
"int"
))
{
return
getSource
().
nextInt
();
return
getSource
().
nextInt
();
}
}
...
@@ -71,6 +78,7 @@ public class RandomValuePropertySource extends PropertySource<Random> {
...
@@ -71,6 +78,7 @@ public class RandomValuePropertySource extends PropertySource<Random> {
environment
.
getPropertySources
().
addAfter
(
environment
.
getPropertySources
().
addAfter
(
StandardEnvironment
.
SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME
,
StandardEnvironment
.
SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME
,
new
RandomValuePropertySource
(
"random"
));
new
RandomValuePropertySource
(
"random"
));
logger
.
trace
(
"RandomValuePropertySource add to Environment"
);
}
}
}
}
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