Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringApplication.setAdditionalProfiles, application-XXX.yml and SpringBoot2.4 #25704

Closed
blacelle opened this issue Mar 16, 2021 · 2 comments
Closed
Labels
status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@blacelle
Copy link
Contributor

blacelle commented Mar 16, 2021

I consider a SpringApplication computing profiles on the fly, to be activated through SpringApplication.setAdditionalProfiles

I used this up to SprintBoot 2.3 to activate configuration in application-XXX.yml files

With SpringBoot 2.4, this seems not functional anymore, even with

Here is a snippet of code demonstrating the issue:

application-reproduce.yml:

reproduce.key: anything
@SpringBootApplication(exclude = org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class, scanBasePackages = "none")
public class RunReproduceMissingApplicationYmlApplication {

	protected RunReproduceMissingApplicationYmlApplication() {
		// hidden
	}

	@Configuration
	public static class SomeConf {

		@Bean
		public Void someBean(Environment env) {
			System.out.println("BEWARE: " + env.getProperty("reproduce.key"));
			return null;
		}

	}

	public static void main(String[] args) {
		System.setProperty("spring.config.use-legacy-processing", "true");
		// Will sysout a null value in SprintBoot 2.4: the bug (while OK with SpringBoot 2.3)
		startApp(args);
		// Will sysout something interesting: expected behavior
		System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "reproduce");
		startApp(args);
	}

	private static void startApp(String[] args) {
		SpringApplication springApp = new SpringApplication(RunReproduceMissingApplicationYmlApplication.class);
		springApp.setWebApplicationType(WebApplicationType.NONE);
		springApp.setAdditionalProfiles("reproduce");
		springApp.run(args);
	}
}

In SpringBoot 2.3, I see twice BEWARE: anything: OK

In SpringBoot 2.4, I see:

...
BEWARE: null
...
BEWARE: anything

which demonstrate explicit profiles definition is OK, but simply exposing them through .setAdditionalProfiles lead them not taken in account for application-XXX.yml property sources.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 16, 2021
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 23, 2021
@philwebb philwebb added this to the 2.4.x milestone Mar 23, 2021
nguyensach added a commit to nguyensach/spring-boot that referenced this issue Mar 29, 2021
Add additional profiles which is set via programmatically, to
Spring's environment property sources when legacy processing is used

This commit updates the following areas:

- Add additionalProfiles field to ConfigFileApplicationListener to
pass SpringApplication 's addition profiles which is set via programmatically,
to ConfigFileApplicationListener from ConfigDataEnvironmentPostProcessor

- Add additional profiles into Spring's environment property sources

- Supplement unit test for SpringApplicationTests

Closes spring-projects#25704
nguyensach added a commit to nguyensach/spring-boot that referenced this issue Mar 29, 2021
Add additional profiles which are set by programmatically, to
Spring's environment property sources when legacy processing is used

This commit updates the following areas:

- Add additionalProfiles field to ConfigFileApplicationListener to
pass SpringApplication's addition profiles which are set by programmatically,
to ConfigFileApplicationListener from ConfigDataEnvironmentPostProcessor

- Add additional profiles into Spring's environment property sources

- Supplement unit test for SpringApplicationTests

Closes spring-projects#25704
nguyensach added a commit to nguyensach/spring-boot that referenced this issue Mar 29, 2021
Add additional profiles which are set by programmatically, to
Spring's environment property sources when legacy processing is used

This commit updates the following areas:

- Add additionalProfiles field to ConfigFileApplicationListener to
pass SpringApplication's addition profiles which are set by programmatically,
to ConfigFileApplicationListener from ConfigDataEnvironmentPostProcessor

- Add additional profiles into Spring's environment property sources

- Supplement unit test for SpringApplicationTests

Closes spring-projects#25704
nguyensach added a commit to nguyensach/spring-boot that referenced this issue Mar 30, 2021
In post-processing the given environment of ConfigDataEnvironmentPostProcessor,
add SpringApplication's additional profiles that are set by programmatically into environment
when legacy processing is used.

This commit updates the following areas:

- Add configureAdditionalProfiles method into ConfigDataEnvironmentPostProcessor,
that add the additional profiles into the given environment.

- When legacy processing is used, call configureAdditionalProfiles method to
add the additional profiles into the given environment.

- Remove unnecessary configureAdditionalProfiles method in SpringApplication.

- Supplement unit test for SpringApplicationTests.

Closes spring-projects#25704
nguyensach added a commit to nguyensach/spring-boot that referenced this issue Mar 30, 2021
In post-processing the given environment of ConfigDataEnvironmentPostProcessor,
add SpringApplication's additional profiles that are set by programmatically into environment
when legacy processing is used.

This commit updates the following areas:

- Add configureAdditionalProfiles method into ConfigDataEnvironmentPostProcessor,
that add the additional profiles into the given environment.

- When legacy processing is used, call configureAdditionalProfiles method to
add the additional profiles into the given environment.

- Remove unnecessary configureAdditionalProfiles method in SpringApplication.

- Supplement unit test for SpringApplicationTests.

Closes spring-projects#25704
@blacelle

This comment has been minimized.

@mbhave
Copy link
Contributor

mbhave commented May 11, 2021

Closing in favor of PR #25817.

@mbhave mbhave closed this as completed May 11, 2021
@mbhave mbhave removed this from the 2.4.x milestone May 11, 2021
@mbhave mbhave added the status: superseded An issue that has been superseded by another label May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants