Skip to content

-Dspring.profiles.active breaks @ActiveProfiles #1109

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

Closed
lrozek opened this issue Jun 17, 2014 · 6 comments
Closed

-Dspring.profiles.active breaks @ActiveProfiles #1109

lrozek opened this issue Jun 17, 2014 · 6 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@lrozek
Copy link

lrozek commented Jun 17, 2014

No description provided.

@snicoll
Copy link
Member

snicoll commented Jun 17, 2014

Could you please provide a better description for your issue? Duplicate of #1095 ?

@lrozek
Copy link
Author

lrozek commented Jun 17, 2014

here is reproduction for this:
https://github.com/lrozek/spring-boot-1109

When Dspring.profiles.active is set then application-${profile}.properties isn't picked up by @activeprofiles

please run to get failing test:
mvn clean test -Dspring.profiles.active=someProfile

@snicoll
Copy link
Member

snicoll commented Jun 17, 2014

You may have tried this without boot and noticed it would work as you expected but that's actually an issue, see SPR-8982.

spring.profiles.active overrides the list of active profiles, which is why your application-test.properties is not read. If you want to add one, you have to use spring.profiles.include.

That is already properly covered in the documentation

@snicoll snicoll closed this as completed Jun 17, 2014
@snicoll snicoll self-assigned this Jun 17, 2014
@lrozek
Copy link
Author

lrozek commented Jun 17, 2014

hello,

thank you for such a quick response.

However, I have a follow-up questions:

  1. shouldn't than
    assertThat( environment.getActiveProfiles(), hasItemInArray( "test" ) )
    fail in first place?

  2. after removing @activeprofiles("test") in
    lrozek/spring-boot-1109@819d528
    I executed mvn clean test -Dspring.profiles.include=test
    It still failed.

  3. This one is indirectly related to the topic. What is a more straightforward approach to override certain properties in tests using boot?

  • @IntegrationTEST does the trick, but I think property file is more desired
  • @activeprofiles("test") and /src/test/resources/application-test.properties also works

However, with boot attempt to simplify things as most as possible I expected that just dropping application.properties in scr/test/resources would do the thing out of the box. Unfortunately, it seems that spring picks up the first one found in a classpath. In my case it was in fact src/test/resources/application.properties, completely ignoring src/main/resources/application.properties.

Thank you for your support

@snicoll
Copy link
Member

snicoll commented Jun 17, 2014

As a general rule, it would be best to post your question on StackOverflow with the spring-boot tag.

  1. Please look at the SPR issue. It should take that override into account but it doesn't. Profile is not a boot specific feature.
  2. Again, look at the documentation. It states it is a property. We agree here that it's a bit strange you can't override that by some other means. Feel free to raise an issue for that.
  3. I would not rely on classpath ordering and overriding resources with the same location is just going to be hard to understand. You already found the ways to do this, profile is probably best if you have several things to tune.

@lrozek
Copy link
Author

lrozek commented Jun 17, 2014

thank you for your answers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants