Skip to content

Document that spring.profiles.active is ignored by @ActiveProfiles#36600

Open
Mohak-Nagaraju wants to merge 1 commit intospring-projects:7.0.xfrom
Mohak-Nagaraju:gh-36269-document-activeprofiles-override-70x
Open

Document that spring.profiles.active is ignored by @ActiveProfiles#36600
Mohak-Nagaraju wants to merge 1 commit intospring-projects:7.0.xfrom
Mohak-Nagaraju:gh-36269-document-activeprofiles-override-70x

Conversation

@Mohak-Nagaraju
Copy link
Copy Markdown

@Mohak-Nagaraju Mohak-Nagaraju commented Apr 5, 2026

Overview

The Test Context Framework does not honor the spring.profiles.active system property when determining active profiles for a test class.

This commit documents that behavior in the following places:

  • @ActiveProfiles Javadoc
  • DefaultActiveProfilesResolver Javadoc
  • Reference manual @ActiveProfiles annotation section
  • Reference manual Context Configuration with Environment
    Profiles section, including a new
    SystemPropertyActiveProfilesResolver example showing how
    to allow spring.profiles.active to override @ActiveProfiles

Related Issues

The Test Context Framework does not honor the
spring.profiles.active system property when determining
active profiles for a test class.

This commit documents that behavior in the @activeprofiles
and DefaultActiveProfilesResolver Javadoc, as well as in
the reference manual. A SystemPropertyActiveProfilesResolver
example is also added showing how to allow
spring.profiles.active to override @activeprofiles.

Closes spring-projectsgh-36269

Signed-off-by: Mohak Nagaraju <98132980+Mohak-Nagaraju@users.noreply.github.com>
Copy link
Copy Markdown
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and for basing it on 7.0.x.

I've requested a few minor changes.

xref:testing/testcontext-framework/ctx-management/env-profiles.adoc#testcontext-ctx-management-env-profiles-ActiveProfilesResolver[`ActiveProfilesResolver`]
and registering it by using the `resolver` attribute of `@ActiveProfiles`.

NOTE: The `spring.profiles.active` system property is not taken into account by the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually is taken into account if you don't declare @ActiveProfiles -- right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! You're right on both points.

  1. The wording is too broad: spring.profiles.active is honored by the TCF when @ActiveProfiles is not declared. I'll narrow it to clarify that this only applies when @ActiveProfiles is present on the test class.
  2. I'll also broaden "system property" to cover the environment variable case as well.

Will update in the next push.

xref:testing/testcontext-framework/ctx-management/env-profiles.adoc#testcontext-ctx-management-env-profiles-ActiveProfilesResolver[`ActiveProfilesResolver`]
and registering it by using the `resolver` attribute of `@ActiveProfiles`.

NOTE: The `spring.profiles.active` system property is not taken into account by the
Copy link
Copy Markdown
Member

@sbrannen sbrannen Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it is usually set as a JVM system property, it's also supported as an environment variable. So, we should revise the wording here.

+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
----
public class SystemPropertyActiveProfilesResolver implements ActiveProfilesResolver {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard. 😉

Perhaps SpringPropertyOverrideActiveProfilesResolver?

Got any better ideas?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Since this specifically targets the JVM system property, would SystemPropertyOverrideActiveProfilesResolver be more accurate than SpringPropertyOverrideActiveProfilesResolver? Happy to use whichever you prefer!

* <p>This annotation will be inherited from an enclosing test class by default.
* See {@link NestedTestConfiguration @NestedTestConfiguration} for details.
*
* <p>Note that the {@code spring.profiles.active} system property is not taken
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as my first comment.

It actually is taken into account if you don't declare @ActiveProfiles -- right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, same fix applies here, will narrow the statement to be specific to when @ActiveProfiles is declared, and broaden "system property" to also mention the environment variable form.

@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue in: test Issues in the test module type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 6, 2026
@sbrannen sbrannen added this to the 7.0.7 milestone Apr 6, 2026
@sbrannen sbrannen changed the title Document that spring.profiles.active is ignored by TCF Document that spring.profiles.active is ignored by @ActiveProfiles Apr 6, 2026
@sbrannen
Copy link
Copy Markdown
Member

sbrannen commented Apr 6, 2026

The Test Context Framework does not honor the spring.profiles.active system property when determining active profiles for a test class.

In line with comments I left in the review, I've modified the title of this PR to reflect that it's the default behavior of @ActiveProfiles which does not honor that Spring property.

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

Labels

in: test Issues in the test module status: waiting-for-feedback We need additional information before we can continue type: documentation A documentation task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants