Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customer Application Environment subclasses
Add custom `ApplicationEnvironment`, `ApplicationServletEnvironment` and `ApplicationReactiveWebEnvironment` subclasses for use with `SpringApplication`. The subclasses all disable the resolution of active and default profiles using properties since this is handled directly by the `ConfigDataEnvironmentPostProcessor`. Closes gh-24892 See gh-24890
- Loading branch information
Showing
15 changed files
with
372 additions
and
22 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...ot-project/spring-boot/src/main/java/org/springframework/boot/ApplicationEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2012-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot; | ||
|
||
import org.springframework.core.env.StandardEnvironment; | ||
|
||
/** | ||
* {@link StandardEnvironment} for typical use in a typical {@link SpringApplication}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class ApplicationEnvironment extends StandardEnvironment { | ||
|
||
@Override | ||
protected String doGetActiveProfilesProperty() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String doGetDefaultProfilesProperty() { | ||
return null; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...spring-boot/src/main/java/org/springframework/boot/ApplicationReactiveWebEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot; | ||
|
||
import org.springframework.boot.web.reactive.context.StandardReactiveWebEnvironment; | ||
|
||
/** | ||
* {@link StandardReactiveWebEnvironment} for typical use in a typical | ||
* {@link SpringApplication}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class ApplicationReactiveWebEnvironment extends StandardReactiveWebEnvironment { | ||
|
||
@Override | ||
protected String doGetActiveProfilesProperty() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String doGetDefaultProfilesProperty() { | ||
return null; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ect/spring-boot/src/main/java/org/springframework/boot/ApplicationServletEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot; | ||
|
||
import org.springframework.web.context.support.StandardServletEnvironment; | ||
|
||
/** | ||
* {@link StandardServletEnvironment} for typical use in a typical | ||
* {@link SpringApplication}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class ApplicationServletEnvironment extends StandardServletEnvironment { | ||
|
||
@Override | ||
protected String doGetActiveProfilesProperty() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String doGetDefaultProfilesProperty() { | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ring-boot/src/test/java/org/springframework/boot/AbstractApplicationEnvironmentTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2012-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.core.env.AbstractEnvironment; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.env.StandardEnvironment; | ||
import org.springframework.mock.env.MockPropertySource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Base class for {@link SpringApplication} {@link Environment} tests. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
public abstract class AbstractApplicationEnvironmentTests { | ||
|
||
@Test | ||
void getActiveProfilesDoesNotResolveProperty() { | ||
StandardEnvironment environment = createEnvironment(); | ||
new MockPropertySource().withProperty("", ""); | ||
environment.getPropertySources().addFirst( | ||
new MockPropertySource().withProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "test")); | ||
assertThat(environment.getActiveProfiles()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void getDefaultProfilesDoesNotResolveProperty() { | ||
StandardEnvironment environment = createEnvironment(); | ||
new MockPropertySource().withProperty("", ""); | ||
environment.getPropertySources().addFirst( | ||
new MockPropertySource().withProperty(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME, "test")); | ||
assertThat(environment.getDefaultProfiles()).containsExactly("default"); | ||
} | ||
|
||
protected abstract StandardEnvironment createEnvironment(); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...oject/spring-boot/src/test/java/org/springframework/boot/ApplicationEnvironmentTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2012-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot; | ||
|
||
import org.springframework.core.env.StandardEnvironment; | ||
|
||
/** | ||
* Tests for {@link ApplicationEnvironment}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class ApplicationEnvironmentTests extends AbstractApplicationEnvironmentTests { | ||
|
||
@Override | ||
protected StandardEnvironment createEnvironment() { | ||
return new ApplicationEnvironment(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...g-boot/src/test/java/org/springframework/boot/ApplicationReactiveWebEnvironmentTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2012-2021 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot; | ||
|
||
import org.springframework.core.env.StandardEnvironment; | ||
|
||
/** | ||
* Tests for {@link ApplicationReactiveWebEnvironment}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class ApplicationReactiveWebEnvironmentTests extends AbstractApplicationEnvironmentTests { | ||
|
||
@Override | ||
protected StandardEnvironment createEnvironment() { | ||
return new ApplicationReactiveWebEnvironment(); | ||
} | ||
|
||
} |
Oops, something went wrong.