简体   繁体   中英

Spring Boot 1.4: set default profile when deploying the app in Tomcat

I have a Spring Boot 1.4 application which has a YAML-based config file. The config file specifies a default profile: prod

spring:
  profiles.active: prod

When I generate a war using Maven and deploy to Tomcat 7, the default profile is not set. Tomcat log:

No active profile set, falling back to default profiles: default

In order to set the default profile in the app deployed in Tomcat, I can pass a System property to Tomcat, like so:

-Dspring.profiles.active=prod

This works, but I would like to use the Spring Boot properties, rather than the System properties for setting a default profile. Is there a reason why the default yaml property file is ignored when the application is deployed in Tomcat?

Just rename your profile to default and add a different name for development, like this:

    spring:
      profiles: development
      devtools:
        restart:
          enabled: false
      thymeleaf:
        mode: HTML
        cache: false
      http:
        multipart:
          max-file-size: 3Mb
          max-request-size: 4Mb

    logging:
      level:
        org.apache: WARN
        org.apache.catalina.webresources.Cache: ERROR
        org.hibernate: WARN
        org.hibernate.SQL: WARN
        org.hibernate.type: WARN
        org.hibernate.jpa.internal: ERROR
        org.springframework: WARN
        org.springframework.data.jpa: WARN
        org.springframework.validation: WARN
        org.springframework.web: WARN
        org.springframework.web.socket: WARN
        org.zkoss: WARN
        com.ultraip: TRACE

    ---

    spring:
      profiles: default
      thymeleaf:
        mode: HTML
      http:
        multipart:
          max-file-size: 3Mb
          max-request-size: 4Mb
      messages:
        cache-seconds: -1
      resources:
        cache-period: 259200

    server:
      port: 80
      session:
        timeout: 86400
      compression:
        enabled: true
        mime-types: "text/html,text/xml,text/css,text/plain,application/json,application/xml,application/javascript"

    security:
      headers:
        cache: false

    logging:
      file: "/var/log/intranet.log"
      level:
        org.apache: WARN
        org.apache.catalina.webresources.Cache: ERROR
        org.hibernate: WARN
        org.hibernate.jpa.internal: ERROR
        org.springframework: WARN
        org.zkoss: WARN
        com.ultraip: INFO

The "---" denotes the start of a different config file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM