2

SpringBoot 2.7.1 with Spring Cloud Config

I have a test

@ActiveProfiles({"local","h2dbmem"})
@SpringBootTest(properties = {"server.ssl.enabled=false"})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@TestPropertySource(locations = "classpath:application-integrationtest.properties")
public class SystemTest {
...
}

and I then run Maven to run the test :

 mvn -Dspring.profiles.include=cloudconfig clean verify

When the test runs, the console says :

The following 3 profiles are active: "cloudconfig", "local", "h2dbmem"

Although this is exactly what I wanted, that it ends up using the JDBC URL and credentials from the h2dbmem profile and not the JDBC URL and credentials from the cloud-config profile, I could not find documentation on why cloudconfig ( supplied via command-line ) was added as the first entry in the list of active profiles after the profiles supplied via the @ActiveProfiles annotation.

To be honest, I was actually expecting the following order of profiles :

The following 3 profiles are active: "local", "h2dbmem", "cloudconfig"

... where the JDBC URL and credentials from cloudconfig are used, but I am glad it was not.

So question is:

Is there specific documentation on the sequence / order of profiles when they are supplied in multiple ways ( annotation, command-line, etc ) ?

Note I am aware of the order and sequence / preference of properties, which is not what I am asking.

jmsjr
  • 148
  • 2
  • 10
  • why don't you create a `test` profile? – Kai-Sheng Yang Jul 08 '22 at 05:48
  • Check out this similar post https://stackoverflow.com/questions/23617831/what-is-the-order-of-precedence-when-there-are-multiple-springs-environment-pro , ideally it picks up from last profile, then second last and so on and so forth ! Also , it is mentioned as part of documentation https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files.profile-specific – Harsh Jul 08 '22 at 05:56
  • 1
    @Harsh that is not what OP is asking. The question is, how does Spring determine the order of profiles when some are given in `@ActiveProfiles` annotation and some in `spring.profiles.include` variable. – 1615903 Jul 08 '22 at 06:25
  • Precisely @1615903 ... That is my / the question. – jmsjr Jul 08 '22 at 07:48

0 Answers0