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
9432ee6a
Commit
9432ee6a
authored
Nov 05, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
124574e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
12 deletions
+32
-12
ResourceProperties.java
...gframework/boot/autoconfigure/web/ResourceProperties.java
+4
-1
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+28
-11
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java
View file @
9432ee6a
...
@@ -19,7 +19,10 @@ package org.springframework.boot.autoconfigure.web;
...
@@ -19,7 +19,10 @@ package org.springframework.boot.autoconfigure.web;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
/**
* Properties used to configure resource handling0
* Properties used to configure resource handling.
*
* @author Phillip Webb
* @since 1.1.0
*/
*/
@ConfigurationProperties
(
prefix
=
"spring.resources"
,
ignoreUnknownFields
=
false
)
@ConfigurationProperties
(
prefix
=
"spring.resources"
,
ignoreUnknownFields
=
false
)
public
class
ResourceProperties
{
public
class
ResourceProperties
{
...
...
spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
9432ee6a
...
@@ -63,8 +63,15 @@ import org.springframework.core.io.ResourceLoader;
...
@@ -63,8 +63,15 @@ import org.springframework.core.io.ResourceLoader;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
hamcrest
.
Matchers
.
containsInAnyOrder
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
/**
* Tests for {@link ConfigFileApplicationListener}.
* Tests for {@link ConfigFileApplicationListener}.
...
@@ -362,7 +369,8 @@ public class ConfigFileApplicationListenerTests {
...
@@ -362,7 +369,8 @@ public class ConfigFileApplicationListenerTests {
"spring.profiles.active:other"
);
"spring.profiles.active:other"
);
this
.
environment
.
addActiveProfile
(
"dev"
);
this
.
environment
.
addActiveProfile
(
"dev"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
containsInAnyOrder
(
"dev"
,
"other"
));
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
containsInAnyOrder
(
"dev"
,
"other"
));
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
),
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
),
equalTo
(
"fromotherpropertiesfile"
));
equalTo
(
"fromotherpropertiesfile"
));
validateProfilePrecedence
(
null
,
"dev"
,
"other"
);
validateProfilePrecedence
(
null
,
"dev"
,
"other"
);
...
@@ -374,39 +382,48 @@ public class ConfigFileApplicationListenerTests {
...
@@ -374,39 +382,48 @@ public class ConfigFileApplicationListenerTests {
"spring.profiles.active:dev,other"
);
"spring.profiles.active:dev,other"
);
this
.
environment
.
addActiveProfile
(
"dev"
);
this
.
environment
.
addActiveProfile
(
"dev"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
containsInAnyOrder
(
"dev"
,
"other"
));
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
containsInAnyOrder
(
"dev"
,
"other"
));
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
),
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
),
equalTo
(
"fromotherpropertiesfile"
));
equalTo
(
"fromotherpropertiesfile"
));
validateProfilePrecedence
(
null
,
"dev"
,
"other"
);
validateProfilePrecedence
(
null
,
"dev"
,
"other"
);
}
}
@Test
@Test
public
void
profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins
()
throws
Exception
{
public
void
profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
environment
,
"spring.profiles.active:other,dev"
);
"spring.profiles.active:other,dev"
);
this
.
environment
.
addActiveProfile
(
"other"
);
this
.
environment
.
addActiveProfile
(
"other"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
containsInAnyOrder
(
"dev"
,
"other"
));
assertThat
(
Arrays
.
asList
(
this
.
environment
.
getActiveProfiles
()),
containsInAnyOrder
(
"dev"
,
"other"
));
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
),
assertThat
(
this
.
environment
.
getProperty
(
"my.property"
),
equalTo
(
"fromdevpropertiesfile"
));
equalTo
(
"fromdevpropertiesfile"
));
validateProfilePrecedence
(
null
,
"other"
,
"dev"
);
validateProfilePrecedence
(
null
,
"other"
,
"dev"
);
}
}
private
void
validateProfilePrecedence
(
String
...
profiles
)
{
private
void
validateProfilePrecedence
(
String
...
profiles
)
{
this
.
initializer
.
onApplicationEvent
(
new
ApplicationPreparedEvent
(
ApplicationPreparedEvent
event
=
new
ApplicationPreparedEvent
(
new
SpringApplication
(),
new
String
[
0
],
new
AnnotationConfigApplicationContext
()));
new
SpringApplication
(),
new
String
[
0
],
new
AnnotationConfigApplicationContext
());
this
.
initializer
.
onApplicationEvent
(
event
);
String
log
=
this
.
out
.
toString
();
String
log
=
this
.
out
.
toString
();
// First make sure that each profile got processed only once
// First make sure that each profile got processed only once
for
(
String
profile
:
profiles
)
{
for
(
String
profile
:
profiles
)
{
assertThat
(
"Wrong number of occurrences for profile '"
+
profile
+
"' --> "
+
log
,
String
reason
=
"Wrong number of occurrences for profile '"
+
profile
StringUtils
.
countOccurrencesOf
(
log
,
createLogForProfile
(
profile
)),
equalTo
(
1
));
+
"' --> "
+
log
;
assertThat
(
reason
,
StringUtils
.
countOccurrencesOf
(
log
,
createLogForProfile
(
profile
)),
equalTo
(
1
));
}
}
// Make sure the order of loading is the right one
// Make sure the order of loading is the right one
for
(
String
profile
:
profiles
)
{
for
(
String
profile
:
profiles
)
{
String
line
=
createLogForProfile
(
profile
);
String
line
=
createLogForProfile
(
profile
);
int
index
=
log
.
indexOf
(
line
);
int
index
=
log
.
indexOf
(
line
);
assertTrue
(
"Loading profile '"
+
profile
+
"' not found in '"
+
log
+
"'"
,
index
!=
-
1
);
assertTrue
(
"Loading profile '"
+
profile
+
"' not found in '"
+
log
+
"'"
,
index
!=
-
1
);
log
=
log
.
substring
(
index
+
line
.
length
(),
log
.
length
());
log
=
log
.
substring
(
index
+
line
.
length
(),
log
.
length
());
}
}
}
}
...
...
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