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
2e1b20ce
Commit
2e1b20ce
authored
May 11, 2021
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Process additional profiles before config files processing"
See gh-25817
parent
6f266145
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
48 deletions
+10
-48
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+0
-1
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+0
-11
ConfigDataEnvironmentPostProcessorTests.java
...ntext/config/ConfigDataEnvironmentPostProcessorTests.java
+9
-3
ConfigFileApplicationListenerLegacyReproTests.java
...config/ConfigFileApplicationListenerLegacyReproTests.java
+0
-11
ConfigFileApplicationListenerTests.java
...ot/context/config/ConfigFileApplicationListenerTests.java
+1
-22
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
2e1b20ce
...
...
@@ -154,7 +154,6 @@ import org.springframework.web.context.support.StandardServletEnvironment;
* @author Madhura Bhave
* @author Brian Clozel
* @author Ethan Rubinson
* @author Nguyen Bao Sach
* @since 1.0.0
* @see #run(Class, String[])
* @see #run(Class[], String[])
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
2e1b20ce
...
...
@@ -605,17 +605,6 @@ class SpringApplicationTests {
assertThat
(
environment
.
getActiveProfiles
()).
containsExactly
(
"bar"
,
"spam"
,
"foo"
);
}
@Test
void
includeProfilesOrder
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
application
.
setEnvironment
(
environment
);
this
.
context
=
application
.
run
(
"--spring.profiles.active=bar,spam"
,
"--spring.profiles.include=foo"
);
// Since Boot 2.4 included profiles should always be last
assertThat
(
environment
.
getActiveProfiles
()).
containsExactly
(
"bar"
,
"spam"
,
"foo"
);
}
@Test
void
addProfilesOrderWithProperties
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorTests.java
View file @
2e1b20ce
...
...
@@ -83,7 +83,6 @@ class ConfigDataEnvironmentPostProcessorTests {
verify
(
this
.
postProcessor
).
getConfigDataEnvironment
(
any
(),
this
.
resourceLoaderCaptor
.
capture
(),
any
());
verify
(
this
.
configDataEnvironment
).
processAndApply
();
assertThat
(
this
.
resourceLoaderCaptor
.
getValue
()).
isInstanceOf
(
DefaultResourceLoader
.
class
);
assertThat
(
this
.
environment
.
getActiveProfiles
()).
isEmpty
();
}
@Test
...
...
@@ -95,7 +94,6 @@ class ConfigDataEnvironmentPostProcessorTests {
verify
(
this
.
postProcessor
).
getConfigDataEnvironment
(
any
(),
this
.
resourceLoaderCaptor
.
capture
(),
any
());
verify
(
this
.
configDataEnvironment
).
processAndApply
();
assertThat
(
this
.
resourceLoaderCaptor
.
getValue
()).
isSameAs
(
resourceLoader
);
assertThat
(
this
.
environment
.
getActiveProfiles
()).
isEmpty
();
}
@Test
...
...
@@ -106,6 +104,14 @@ class ConfigDataEnvironmentPostProcessorTests {
verify
(
this
.
postProcessor
).
getConfigDataEnvironment
(
any
(),
any
(),
this
.
additionalProfilesCaptor
.
capture
());
verify
(
this
.
configDataEnvironment
).
processAndApply
();
assertThat
(
this
.
additionalProfilesCaptor
.
getValue
()).
containsExactly
(
"dev"
);
}
@Test
void
postProcessEnvironmentWhenNoActiveProfiles
()
{
willReturn
(
this
.
configDataEnvironment
).
given
(
this
.
postProcessor
).
getConfigDataEnvironment
(
any
(),
any
(),
any
());
this
.
postProcessor
.
postProcessEnvironment
(
this
.
environment
,
this
.
application
);
verify
(
this
.
postProcessor
).
getConfigDataEnvironment
(
any
(),
this
.
resourceLoaderCaptor
.
capture
(),
any
());
verify
(
this
.
configDataEnvironment
).
processAndApply
();
assertThat
(
this
.
environment
.
getActiveProfiles
()).
isEmpty
();
}
...
...
@@ -123,7 +129,7 @@ class ConfigDataEnvironmentPostProcessorTests {
}
@Test
void
postProcessEnvironmentWhenHasAdditionalProfiles
ViaProgrammaticallySetting
AndUseLegacyProcessing
()
{
void
postProcessEnvironmentWhenHasAdditionalProfilesAndUseLegacyProcessing
()
{
this
.
application
.
setAdditionalProfiles
(
"dev"
);
ConfigDataEnvironmentPostProcessor
.
LegacyConfigFileApplicationListener
legacyListener
=
mock
(
ConfigDataEnvironmentPostProcessor
.
LegacyConfigFileApplicationListener
.
class
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerLegacyReproTests.java
View file @
2e1b20ce
...
...
@@ -168,17 +168,6 @@ class ConfigFileApplicationListenerLegacyReproTests {
assertVersionProperty
(
this
.
context
,
"A"
,
"C"
,
"A"
);
}
@Test
void
additionalProfilesViaProgrammaticallySetting
()
{
// gh-25704
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
application
.
setAdditionalProfiles
(
"dev"
);
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getEnvironment
().
acceptsProfiles
(
Profiles
.
of
(
"dev"
))).
isTrue
();
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"my.property"
)).
isEqualTo
(
"fromdevpropertiesfile"
);
}
private
void
assertVersionProperty
(
ConfigurableApplicationContext
context
,
String
expectedVersion
,
String
...
expectedActiveProfiles
)
{
assertThat
(
context
.
getEnvironment
().
getActiveProfiles
()).
isEqualTo
(
expectedActiveProfiles
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
View file @
2e1b20ce
...
...
@@ -1153,17 +1153,6 @@ class ConfigFileApplicationListenerTests {
@Test
void
additionalProfilesCanBeIncludedFromProgrammaticallySetting
()
{
// gh-25704
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
application
.
setAdditionalProfiles
(
"dev"
);
this
.
context
=
application
.
run
();
// Active profile should win over default
assertThat
(
this
.
context
.
getEnvironment
().
getProperty
(
"my.property"
)).
isEqualTo
(
"fromdevpropertiesfile"
);
}
@Test
void
twoAdditionalProfilesCanBeIncludedFromProgrammaticallySetting
()
{
// gh-25704
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
...
...
@@ -1173,21 +1162,11 @@ class ConfigFileApplicationListenerTests {
}
@Test
void
includeProfilesOrder
()
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.profiles.active=bar,spam"
,
"--spring.profiles.include=foo"
);
// Before Boot 2.4 included profiles should always be first
assertThat
(
this
.
context
.
getEnvironment
().
getActiveProfiles
()).
containsExactly
(
"foo"
,
"bar"
,
"spam"
);
}
@Test
void
addProfilesOrder
()
{
void
activeProfilesShouldTakePrecedenceOverAdditionalProfiles
()
{
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
application
.
setAdditionalProfiles
(
"foo"
);
this
.
context
=
application
.
run
(
"--spring.profiles.active=bar,spam"
);
// Before Boot 2.4 additional profiles should always be first
assertThat
(
this
.
context
.
getEnvironment
().
getActiveProfiles
()).
containsExactly
(
"foo"
,
"bar"
,
"spam"
);
}
...
...
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