【问题标题】:Spring Boot configuration from application.properties来自 application.properties 的 Spring Boot 配置
【发布时间】:2018-11-28 11:22:34
【问题描述】:

我看到当 Spring Boot 项目是 war 文件并在外部 Tomcat 上运行时,应用程序上下文中的值没有被拾取。

我该如何解决这个问题?

示例 - server.port=8096 但加载时的端口仍然是 8080

【问题讨论】:

  • 请提供您应用中的相关代码sn-ps。
  • server.* 属性仅适用于嵌入式容器,而不适用于部署到外部 tomcat 时。

标签: java spring-boot tomcat configuration war


【解决方案1】:

您可能需要将属性文件移到项目之外。 src/main/resources 下的 application.properties 将保留但引用外部属性文件。例如

spring.config.location=./tomcatfolder/external-application.properties

【讨论】: