Skip to content

Improve documentation: behaviour for overriding profiles defined by "@ActiveProfiles" through "-Dspring.profiles.active" #36269

@manueljordan

Description

@manueljordan

Hello Spring Team

Currently and so far in SF 7.0

For a Test class when it uses @ActiveProfiles it works as expected by applying the profile(s) defined through the profiles element. But is not possible override this through the command by -Dspring.profiles.active=...

In other words

  • Override @ActiveProfiles({"dev","cache"}) by -Dspring.profiles.active=prod,-no-cache

Of course, if the test class comments @ActiveProfiles({"dev","cache"}) then -Dspring.profiles.active=prod,-no-cache works in peace

Is there an official explicit indication and explanation about

  1. Why is not possible override the profiles @ActiveProfiles through -Dspring.profiles.active=...?
  2. How to accomplish the desired goal?

I already did do a research in the official documentation at:

And there is nothing about to resolve 1 and 2

According with my understanding to accomplish (2) is

a. Implement the ActiveProfilesResolver interface to take in consideration the spring.profiles.active option over the profiles element. Of course it only if the former exists, otherwise the latter works in peace (practically the current behavioir of the unique and default implementation: the DefaultActiveProfilesResolver class)
b. Finally refer this implementation through the resolver element as @ActiveProfiles(profiles={"dev","cache"}, resolver=ImprovedActiveProfilesResolver.class)

Thanks for your understanding

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions