Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/modules/ROOT/pages/server/environment-repository.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ If there are profile-specific YAML (or properties) files, these are also applied
Higher precedence translates to a `PropertySource` listed earlier in the `Environment`.
(These same rules apply in a standalone Spring Boot application.)

For the sample client above, a native, Git or SVN repository lists the following files of one search location in this order, from the highest precedence to the lowest:

. `foo-mysql.yml`
. `application-mysql.yml`
. `foo-dev.yml`
. `application-dev.yml`
. `foo.yml`
. `application.yml`

The server loads the shared `application` files as well as the files named after the application, so a file such as `foo-dev.yml` applies only to the `foo` application and can hold settings that one application needs for one profile.

You can set `spring.cloud.config.server.accept-empty` to `false` so that Server would return a HTTP 404 status, if the application is not found. By default, this flag is set to `true`.

NOTE: You cannot place `spring.main.*` properties in a remote `EnvironmentRepository`. These properties are used as part of the application initialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @author Spencer Gibb
* @author Venil Noronha
* @author Daniel Lavoie
* @author Sharang Gupta
*/
public class NativeEnvironmentRepositoryTests {

Expand Down Expand Up @@ -71,6 +72,20 @@ public void vanilla() {
assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion");
}

@Test
public void applicationAndProfileSpecificFilesFollowSpringBootPrecedence() {
this.repository.setSearchLocations("classpath:/test/precedence/");

Environment environment = this.repository.findOne("orders", "dev,mysql", null);

assertThat(environment.getPropertySources()).extracting(PropertySource::getName)
.containsExactly("classpath:/test/precedence/orders-mysql.yml",
"classpath:/test/precedence/application-mysql.yml", "classpath:/test/precedence/orders-dev.yml",
"classpath:/test/precedence/application-dev.yml", "classpath:/test/precedence/orders.yml",
"classpath:/test/precedence/application.yml");
assertThat(environment.getPropertySources().get(0).getSource().get("source")).isEqualTo("orders-mysql.yml");
}

@Test
public void ignoresExistingProfile() {
System.setProperty("spring.profiles.active", "cloud");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: application-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: orders-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: orders-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source: orders.yml
Loading