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

Make configurable the key used to specify active profiles (spring.profiles.active) [SPR-8875] #13516

Closed
spring-projects-issues opened this issue Nov 24, 2011 · 4 comments
Labels
in: core status: declined type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 24, 2011

jean opened SPR-8875 and commented

For background, see https://jira.springsource.org/browse/SPR-8869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=73077

Currently the key used to read Spring active profiles is named 'spring.profiles.active' and it can't be changed.

There are several use cases where making this key fully configurable would reveal highly useful.

e.g. 'myapp1_profiles_active', 'myapp2_profiles_active', 'foobar_x', etc.

One idea behind the newly introduced Spring profile feature is to be able to trigger a specific configuration in an application without changing the content of the application, just by introducing a variable that will be read by Spring at startup.

This key value can be read from the system environment variable (no additional parameter needed when starting an application) or from the java system properties, traditionally passed with -Dkey=value in the command line used to stat the application.

When you have several applications running on a single machine, such as when you work on different applications as a developer, you may quickly end up needing to pass different spring active profile values to each application.

This isn't possible with system environment variable. You can only specify different spring.profiles.active value per application through Java system properties, which can become quiet cumbersome when you have many run/debug configuration in your IDE, or when you use maven command line.

Allowing for a fully configurable key through a simple annotation, something like @ActiveProfilesPropertyName("myapp_profiles_active"), or it's equivalent in XML, would allow for a higher level of configurability.
This would be used only by the ones that need this higher level, conventional key value would apply by default.


Reference URL: https://jira.springsource.org/browse/SPR-8869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=73077

1 votes, 2 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 25, 2011

Chris Beams commented

Hi Jean,

Thanks for creating this separate issue. As I mentioned in #13510, I will leave this open in the 3.2 backlog for a while to see if there is indeed interest from others in such a feature. Without a pretty strong additional arguments and support, we won't add first-class support for something like this.

As you originally mentioned, there is a quite reasonable way of acheiving this on your own, doing something like the following from within an ApplicationContextInitializer:

ConfigurableEnvironment env = context.getEnvironment();
env.setActiveProfiles(env.getProperty("APPX_SPRING_PROFILES_ACTIVE"));

Cheers,

Chris

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 25, 2011

jean commented

Hi Chris,

it's good that you mention the ApplicationContextInitializer.
It's a quite convenient workaround for a webapp, but what would be its equivalent for a standalone application or for a test context for that matter?
I haven't been able to find something similar in the code when not in a web context.

cheers
Jean

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 25, 2011

Chris Beams commented

In a standalone or other non-web application you would just work against the ApplicationContext directly. The code sample I gave above would work equally as well there. In the Spring TestContext framework, you can use the new @ActiveProfiles annotation for this purpose.

Chris

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 27, 2013

Chris Beams commented

Resolving as "Won't Fix", per the reasons and alternative approaches discussed in the comment thread.

@spring-projects-issues spring-projects-issues added status: declined type: enhancement in: core labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: declined type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant