What is diff between spring.profiles.active vs spring.config.activate.on-profile?
Asked Answered
D

1

15

What is exact difference between spring.profiles.active and spring.config.activate.on-profile?

"WARN","msg":"Property 'spring.profiles' imported from location 'class path resource [application.yaml]' is invalid and should be replaced with 'spring.config.activate.on-profile' [origin: class path resource [application.yaml]

Digiacomo answered 21/7, 2022 at 8:8 Comment(2)
I believe they both serve the same purpose, however, spring.profiles works up to Spring boot 2.3 and spring.config.activate.on-profile is for Spring Boot 2.4 onwards. More info here: spring.io/blog/2020/08/14/…Pegpega
if we have both in out applican.yml file which will take preference ? spring.profiles.active=local or spring.config.activate.on-profile=local ?Craps
S
32

spring.profiles.active can be used to specify which profiles are always active.
An example from the documentation:

spring:
  profiles:
    active: "production"

spring.config.activate.on-profile (known as spring.profiles before Spring Boot 2.4) can be used to mark a configuration file segment profile-specific.
An example from the documentation:

server:
  port: 9000
---
spring:
  config:
    activate:
      on-profile: "development"
server:
  port: 9001
---
spring:
  config:
    activate:
      on-profile: "production"
server:
  port: 0

In the preceding example, the default port is 9000. However, if the Spring profile called ‘development’ is active, then the port is 9001. If ‘production’ is active, then the port is 0.

Another change in Spring Boot 2.4 was that the spring.profiles.active property is no longer allowed in combination with spring.config.activate.on-profile. (See this blog post for details.)

Sorcerer answered 20/9, 2022 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.