11

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]

Prashant kamble
  • 259
  • 2
  • 4
  • 11
  • 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: https://spring.io/blog/2020/08/14/config-file-processing-in-spring-boot-2-4 – Kris Jul 21 '22 at 09:13
  • if we have both in out applican.yml file which will take preference ? spring.profiles.active=local or spring.config.activate.on-profile=local ? – newcoder Sep 19 '22 at 20:38

1 Answers1

20

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.)

snorbi
  • 2,590
  • 26
  • 36