Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring not overriding active profile from command line [duplicate]

Here is my application.yml file:

spring:
  freemarker:
    template-loader-path: classpath:/templates

  datasource:
    url: jdbc:postgresql://localhost:5432/myapp
    username: postgres
    password: password
    driver-class-name: org.postgresql.Driver

  jpa:
    show-sql: true
    properties:
      hibernate:
        enable_lazy_load_no_trans: false
        jdbc:
          lob:
            non_contextual_creation: true
        dialect: org.hibernate.dialect.PostgreSQLDialect
    hibernate:
      ddl-auto: create-drop


---

spring:
  profiles:
    active: development


---

spring:
  profiles: staging

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: update

logging:
  level:
    root: DEBUG

---

spring:
  profiles: production

  jpa:
    show-sql: false
    hibernate:
      ddl-auto: update

I run the application using:

java -jar application.jar -Dspring.profiles.active=staging

In the log, I can see that spring boot prints out: The following profiles are active: development

So why isn't the active profile set to staging even though I explicitly set it in the command line args?

like image 996
conquester Avatar asked Dec 31 '18 12:12

conquester


1 Answers

The order matters. To set a system property, use

java -jar -Dspring.profiles.active=staging application.jar

The line you mentioned passes an application argument.

like image 87
Andrew Tobilko Avatar answered Sep 16 '22 16:09

Andrew Tobilko