gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:39:45 31 4
gpt4 key购买 nike

我有一个 Spring Boot 1.4 应用程序,它有一个基于 YAML 的配置文件。配置文件指定了默认配置文件:prod

spring:
profiles.active: prod

当我使用 Maven 生成 war 并部署到 Tomcat 7 时,未设置默认配置文件。 Tomcat日志:
No active profile set, falling back to default profiles: default

为了在 Tomcat 中部署的应用程序中设置默认配置文件,我可以将 System 属性传递给 Tomcat,如下所示:
-Dspring.profiles.active=prod

这有效,但我想使用 Spring Boot 属性,而不是系统属性来设置默认配置文件。
在Tomcat中部署应用程序时,默认yaml属性文件被忽略是否有原因?

最佳答案

只需将您的配置文件重命名为 default 并添加不同的开发名称,如下所示:

    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

“---”表示不同配置文件的开始

关于 Spring Boot 1.4 : set default profile when deploying the app in Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39350690/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com