Honour spring.profiles.include even when .active has not been set
393cfe50 expanded the scope of spring.profiles.include so that it
could be used in any property source, and not just in a configuration
file. However, it did so in such a way that it would only take effect
when used outside of a configuration file if spring.profiles.active
was also set.
This commit updates ConfigFileApplicationListener so that included
profiles are activated when spring.profiles.active has not be set.
Closes gh-8244
			
			
This commit is contained in:
		
							parent
							
								
									9a2793356b
								
							
						
					
					
						commit
						7dd8e8c4b8
					
				| 
						 | 
				
			
			@ -388,7 +388,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		private Set<Profile> initializeActiveProfiles() {
 | 
			
		||||
			if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)) {
 | 
			
		||||
			if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)
 | 
			
		||||
					&& !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) {
 | 
			
		||||
				return Collections.emptySet();
 | 
			
		||||
			}
 | 
			
		||||
			// Any pre-existing active profiles set via property sources (e.g. System
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -851,6 +851,15 @@ public class ConfigFileApplicationListenerTests {
 | 
			
		|||
				.isFalse();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	public void profileCanBeIncludedWithoutAnyBeingActive() throws Exception {
 | 
			
		||||
		SpringApplication application = new SpringApplication(Config.class);
 | 
			
		||||
		application.setWebEnvironment(false);
 | 
			
		||||
		this.context = application.run("--spring.profiles.include=dev");
 | 
			
		||||
		String property = this.context.getEnvironment().getProperty("my.property");
 | 
			
		||||
		assertThat(property).isEqualTo("fromdevpropertiesfile");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	public void activeProfilesCanBeConfiguredUsingPlaceholdersResolvedAgainstTheEnvironment()
 | 
			
		||||
			throws Exception {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue