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
9be4b571
Commit
9be4b571
authored
Dec 15, 2015
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add constants for well-known PropertySource names
Closes gh-4776
parent
543a746d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
10 deletions
+25
-10
ConfigFileApplicationListener.java
...rk/boot/context/config/ConfigFileApplicationListener.java
+10
-5
RandomValuePropertySource.java
...mework/boot/context/config/RandomValuePropertySource.java
+10
-1
PropertiesConfigurationFactoryTests.java
...mework/boot/bind/PropertiesConfigurationFactoryTests.java
+2
-2
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+2
-1
RandomValuePropertySourceTests.java
...k/boot/context/config/RandomValuePropertySourceTests.java
+1
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
View file @
9be4b571
...
...
@@ -131,6 +131,11 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
*/
public
static
final
int
DEFAULT_ORDER
=
Ordered
.
HIGHEST_PRECEDENCE
+
10
;
/**
* Name of the application configuration {@link PropertySource}.
*/
public
static
final
String
APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME
=
"applicationConfigurationProperties"
;
private
final
DeferredLog
logger
=
new
DeferredLog
();
private
String
searchLocations
;
...
...
@@ -599,14 +604,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
static
class
ConfigurationPropertySources
extends
EnumerablePropertySource
<
Collection
<
PropertySource
<?>>>
{
private
static
final
String
NAME
=
"applicationConfigurationProperties"
;
private
final
Collection
<
PropertySource
<?>>
sources
;
private
final
String
[]
names
;
ConfigurationPropertySources
(
Collection
<
PropertySource
<?>>
sources
)
{
super
(
NAME
,
sources
);
super
(
APPLICATION_CONFIGURATION_PROPERTY_SOURCE_
NAME
,
sources
);
this
.
sources
=
sources
;
List
<
String
>
names
=
new
ArrayList
<
String
>();
for
(
PropertySource
<?>
source
:
sources
)
{
...
...
@@ -630,9 +635,9 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
public
static
void
finishAndRelocate
(
MutablePropertySources
propertySources
)
{
String
name
=
APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME
;
ConfigurationPropertySources
removed
=
(
ConfigurationPropertySources
)
propertySources
.
get
(
ConfigurationPropertySources
.
NAME
);
String
name
=
ConfigurationPropertySources
.
NAME
;
.
get
(
name
);
if
(
removed
!=
null
)
{
for
(
PropertySource
<?>
propertySource
:
removed
.
sources
)
{
if
(
propertySource
instanceof
EnumerableCompositePropertySource
)
{
...
...
@@ -646,7 +651,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
propertySources
.
addAfter
(
name
,
propertySource
);
}
}
propertySources
.
remove
(
ConfigurationPropertySources
.
NAME
);
propertySources
.
remove
(
APPLICATION_CONFIGURATION_PROPERTY_SOURCE_
NAME
);
}
}
...
...
spring-boot/src/main/java/org/springframework/boot/context/config/RandomValuePropertySource.java
View file @
9be4b571
...
...
@@ -51,6 +51,11 @@ import org.springframework.util.StringUtils;
*/
public
class
RandomValuePropertySource
extends
PropertySource
<
Random
>
{
/**
* Name of the random {@link PropertySource}.
*/
public
static
final
String
RANDOM_PROPERTY_SOURCE_NAME
=
"random"
;
private
static
final
String
PREFIX
=
"random."
;
private
static
Log
logger
=
LogFactory
.
getLog
(
RandomValuePropertySource
.
class
);
...
...
@@ -59,6 +64,10 @@ public class RandomValuePropertySource extends PropertySource<Random> {
super
(
name
,
new
Random
());
}
public
RandomValuePropertySource
()
{
this
(
RANDOM_PROPERTY_SOURCE_NAME
);
}
@Override
public
Object
getProperty
(
String
name
)
{
if
(!
name
.
startsWith
(
PREFIX
))
{
...
...
@@ -126,7 +135,7 @@ public class RandomValuePropertySource extends PropertySource<Random> {
public
static
void
addToEnvironment
(
ConfigurableEnvironment
environment
)
{
environment
.
getPropertySources
().
addAfter
(
StandardEnvironment
.
SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME
,
new
RandomValuePropertySource
(
"random"
));
new
RandomValuePropertySource
(
RANDOM_PROPERTY_SOURCE_NAME
));
logger
.
trace
(
"RandomValuePropertySource add to Environment"
);
}
...
...
spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java
View file @
9be4b571
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
5
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.
...
...
@@ -126,7 +126,7 @@ public class PropertiesConfigurationFactoryTests {
MutablePropertySources
propertySources
=
new
MutablePropertySources
();
propertySources
.
addLast
(
new
SystemEnvironmentPropertySource
(
"systemEnvironment"
,
Collections
.<
String
,
Object
>
singletonMap
(
"FOO_BAR_NAME"
,
"blah"
)));
propertySources
.
addLast
(
new
RandomValuePropertySource
(
"random"
));
propertySources
.
addLast
(
new
RandomValuePropertySource
());
setupFactory
();
this
.
factory
.
setPropertySources
(
propertySources
);
this
.
factory
.
afterPropertiesSet
();
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
9be4b571
...
...
@@ -519,7 +519,8 @@ public class ConfigFileApplicationListenerTests {
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
contains
(
"dev"
));
assertThat
(
property
,
equalTo
(
"fromdevprofile"
));
ConfigurationPropertySources
propertySource
=
(
ConfigurationPropertySources
)
this
.
environment
.
getPropertySources
().
get
(
"applicationConfigurationProperties"
);
.
getPropertySources
()
.
get
(
ConfigFileApplicationListener
.
APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME
);
Collection
<
org
.
springframework
.
core
.
env
.
PropertySource
<?>>
sources
=
propertySource
.
getSource
();
assertEquals
(
2
,
sources
.
size
());
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/RandomValuePropertySourceTests.java
View file @
9be4b571
...
...
@@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue;
*/
public
class
RandomValuePropertySourceTests
{
private
RandomValuePropertySource
source
=
new
RandomValuePropertySource
(
"random"
);
private
RandomValuePropertySource
source
=
new
RandomValuePropertySource
();
@Test
public
void
notRandom
()
{
...
...
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