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

AbstractEnvironment addActiveProfile ignores profiles activated with properties [SPR-9944] #14577

Closed
spring-projects-issues opened this issue Nov 1, 2012 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Jan Kronquist opened SPR-9944 and commented

addActiveProfile does not check if profiles are initiated using a property. This means that you have to call getActiveProfiles() before calling addActiveProfile!

See code below:

protected Set<String> doGetActiveProfiles() {
	if (this.activeProfiles.isEmpty()) {
		String profiles = this.getProperty(ACTIVE_PROFILES_PROPERTY_NAME);
		if (StringUtils.hasText(profiles)) {
			setActiveProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles)));
		}
	}
	return this.activeProfiles;
}

public void addActiveProfile(String profile) {
	if (this.logger.isDebugEnabled()) {
		this.logger.debug(format("Activating profile '%s'", profile));
	}
	this.validateProfile(profile);
	this.activeProfiles.add(profile);
}

Affects: 3.1.3

Referenced from: commits c94bc2e

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Thanks, Jan.

commit c94bc2e709ab00b154fdedc613b92b093dc0d029
Author: Chris Beams <cbeams@vmware.com>
Commit: Chris Beams <cbeams@vmware.com>

    Respect spring.profiles.active in #addActiveProfile
    
    Prior to this commit, calls to ConfigurableEnvironment#addActiveProfile
    would cause any active profile values provided via the
    "spring.profiles.active" property to be ignored.
    
    Now these two mechanisms can be used in conjunction and work as
    expected.
    
    Issue: SPR-9944

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant