Skip to content

Add application listener to locate property sources during bootstrap #1228

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

Conversation

ryanjbaxter
Copy link
Contributor

Also adds support for activating profiles using spring.profiles.active from bootstrap property source listeners.

@ryanjbaxter ryanjbaxter requested a review from spencergibb April 21, 2023 19:21
@ryanjbaxter
Copy link
Contributor Author

Partial fix for spring-cloud/spring-cloud-config#1922

@ryanjbaxter
Copy link
Contributor Author

Profiles from the bootstrap context get applied to the child context here
https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java#L372
When ParentContextApplicationContextInitializer.initialize sets the parent context to the bootstrap context it inherits the active profiles.

This all happens after the environment is prepared when config data runs.
Here is where we prepare the environment
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java#L306

And here is where the parent context is set
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java#L310

@ryanjbaxter ryanjbaxter force-pushed the run-bootstrap-propertysource-locators-during-bootstrap branch from 45c6e71 to 1fa3b25 Compare April 26, 2023 23:58
Also adds support for activating profiles using spring.profiles.active from bootstrap property source listeners.

Allow profiles to be passed from bootstrap context to main application context
Also adds support for activating profiles using spring.profiles.active from bootstrap property source listeners.

Allow profiles to be passed from bootstrap context to main application context

Updating version in docs
… of github.com:ryanjbaxter/spring-cloud-commons into run-bootstrap-propertysource-locators-during-bootstrap
// environment. This allows any profiles activated during bootstrap to be
// activated when
// config data runs in the main application context.
environment.setActiveProfiles(context.getEnvironment().getActiveProfiles());
Copy link
Contributor

@qnnn qnnn Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanjbaxter Is it possible to bind configurations like spring.main and spring.banner within this code segment? These configurations work when loaded through ConfigDataEnvironmentPostProcessor, but they do not take effect when loaded through BootstrapApplicationListener. It appears that the issue might be because PropertySourceBootstrapConfiguration is actually executed in the main context's initializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants