-
Notifications
You must be signed in to change notification settings - Fork 38.4k
@ActiveProfiles
is not honored on @SpringBootApplication
even in test context
#32771
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
Comments
PS. change your test to @ActiveProfiles("test")
@SpringBootTest
class BugPropertySourceApplicationTests {
@Autowired
Environment env;
@Test
void contextLoads() {
System.out.println("Active profile:" + Arrays.toString(env.getActiveProfiles()));
}
} and you'll see its working and no banner appeared in the stdout |
I'm aware of that, which is why I said "even when in a test context". Since Spring Boot needs some kind of context class I always use the same |
@ActiveProfiles
is not honored on @SpringBootApplication
even in test context
That is indeed intentional,
In other words, they are not honored on a In light of that, I've closed this issue as invalid. However, I'll improve the wording in the Javadoc for such annotations in #32772. |
To provide a bit more context to the "why", it's a test-only annotation (as you are aware) that participates in the context key that the TCF uses to cache contexts, and this needs to be known upfront. Irrespective of that, you can't decide to activate a profile in flight (i.e. while processing configuration classes). That hopefully explains why you can't expect to use it elsewhere than the test class. It's a bit like enabling an extra profile on |
yeah, I'm speculating I thought it would work because the |
It would seem that
ActiveProfiles
isn't detected when on aSpringBootApplication
maybe this is intentional, but I guess I was expecting it to be respected on a configuration.bug-property-source.tar.gz
original bug response: spring-projects/spring-boot#40620 (comment)
The text was updated successfully, but these errors were encountered: