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
889a97a6
Commit
889a97a6
authored
Jan 09, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default spring.config.location to file: if no prefix supplied
Fixes gh-198
parent
aebaa580
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
ConfigFileApplicationListener.java
.../boot/context/listener/ConfigFileApplicationListener.java
+10
-1
ConfigFileApplicationListenerTests.java
.../context/listener/ConfigFileApplicationListenerTests.java
+21
-2
No files found.
spring-boot/src/main/java/org/springframework/boot/context/listener/ConfigFileApplicationListener.java
View file @
889a97a6
...
...
@@ -263,7 +263,16 @@ public class ConfigFileApplicationListener implements
private
PropertySource
<?>
load
(
ConfigurableEnvironment
environment
,
ResourceLoader
resourceLoader
,
String
location
,
String
profile
)
{
location
=
environment
.
resolvePlaceholders
(
location
);
String
path
=
environment
.
resolvePlaceholders
(
location
);
if
(
LOCATION_VARIABLE
.
equals
(
location
)
&&
!
path
.
contains
(
"$"
))
{
if
(!
path
.
contains
(
":"
))
{
path
=
"file:"
+
path
;
}
path
=
StringUtils
.
cleanPath
(
path
);
}
location
=
path
;
String
suffix
=
"."
+
StringUtils
.
getFilenameExtension
(
location
);
Class
<?>
type
=
this
.
propertySourceAnnotations
.
configuration
(
location
);
...
...
spring-boot/src/test/java/org/springframework/boot/context/listener/ConfigFileApplicationListenerTests.java
View file @
889a97a6
...
...
@@ -153,8 +153,8 @@ public class ConfigFileApplicationListenerTests {
@Test
public
void
yamlProfileCanBeChanged
()
throws
Exception
{
EnvironmentTestUtils
.
addEnviroment
(
this
.
environment
,
"spring.profiles.active:prod"
);
EnvironmentTestUtils
.
addEnviroment
(
this
.
environment
,
"spring.profiles.active:prod"
);
this
.
initializer
.
setNames
(
"testsetprofiles"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()).
toString
(),
...
...
@@ -189,6 +189,25 @@ public class ConfigFileApplicationListenerTests {
assertThat
(
this
.
environment
.
getProperty
(
"foo"
),
equalTo
(
"bucket"
));
}
@Test
public
void
specificResourceAsFile
()
throws
Exception
{
String
location
=
"file:src/test/resources/specificlocation.properties"
;
EnvironmentTestUtils
.
addEnviroment
(
this
.
environment
,
"spring.config.location:"
+
location
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertThat
(
this
.
environment
.
getPropertySources
().
contains
(
location
),
is
(
true
));
}
@Test
public
void
specificResourceDefaultsToFile
()
throws
Exception
{
String
location
=
"src/test/resources/specificlocation.properties"
;
EnvironmentTestUtils
.
addEnviroment
(
this
.
environment
,
"spring.config.location:"
+
location
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertThat
(
this
.
environment
.
getPropertySources
().
contains
(
"file:"
+
location
),
is
(
true
));
}
@Test
public
void
propertySourceAnnotation
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
WithPropertySource
.
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