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

BootstrapApplicationListener overrides custom environment #596

Open
samjoseph opened this issue Aug 29, 2019 · 7 comments
Open

BootstrapApplicationListener overrides custom environment #596

samjoseph opened this issue Aug 29, 2019 · 7 comments

Comments

@samjoseph
Copy link

The BootstrapApplicationListener defines its own environment when it creates the Spring Application using the Spring Builder. This overrides the custom environment we have provided for our application during the initial application run invocation.

We specify a custom environment class for our application for reasons specified in this issue

The BootstrapApplicationListener should provide a way for applications to specify their own environment class instead of defining its bootstrapEnvironment using new StandardEnvironment().

private ConfigurableApplicationContext bootstrapServiceContext( ConfigurableEnvironment environment, final SpringApplication application, String configName) { **StandardEnvironment bootstrapEnvironment = new StandardEnvironment();** MutablePropertySources bootstrapProperties = bootstrapEnvironment .getPropertySources(); for (PropertySource<?> source : bootstrapProperties) { bootstrapProperties.remove(source.getName()); }

@spencergibb
Copy link
Member

I'm a bit unsure how we would go about doing that. It's too early in the lifecycle to have a bean. The only other thought would be to extract env creation to a protected method and then you'd need to setup your own entry in spring.factories in org.springframework.context.ApplicationListener and disable the provided one. @dsyer thoughts?

@dsyer
Copy link
Contributor

dsyer commented Sep 16, 2019

I can't think of a reason you'd want to override the environment implementation. Maybe we need to dig into the reason for asking in the first place, in case there's a better solution.

@spencergibb
Copy link
Member

Alright, we'll wait for the OP

@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@samjoseph
Copy link
Author

@dsyer

This is the reason why we have a overridden environment implementation

Consider following property
sam.credential.property=MockCredentialVault("Test")

Where MockCredentialVault is a type of Credential Vault System we want to access with the "Test" value

So we need to have access to all property sources since the MockCredentialVault("Test") could also be in a different file

application.properties
sam.credential.property=${vault.system.placeholder}

prod.properties
vault.system.placeholder=MockCredentialVault("Test")

We felt that the a custom environment would be a better place to do this resolution as it has access to all property sources and in the case of custom environment we also have a central location to cache & refresh the retrieved credentials.

@spencergibb
Copy link
Member

That is very unusual and so far no one else has requested it. Let's see if there is more interest.

@dsyer
Copy link
Contributor

dsyer commented Sep 25, 2019

I'm also still a bit unclear about why this can't be achieved with an EnvironmentPostProcessor. There are some lifecycle issues with EPPs that we are vaguely aware of (some implementations don't like to be run twice), but without a concrete code sample it's hard to say if this is one of those. Can you create a sample app (maybe one that doesn't actually use Vault, so it is easy to tinker with)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants