【发布时间】:2016-12-04 05:28:34
【问题描述】:
我正在使用 Spring Boot 应用程序。我将我的代码部署到三个不同的环境(本地、开发、整数)。目前 logback.xml 从 application.properties 读取。如何让它从 application-dev.properties、application-int.properties.. 中读取,具体取决于应用程序已部署的环境?
【问题讨论】:
标签: spring-boot logback
我正在使用 Spring Boot 应用程序。我将我的代码部署到三个不同的环境(本地、开发、整数)。目前 logback.xml 从 application.properties 读取。如何让它从 application-dev.properties、application-int.properties.. 中读取,具体取决于应用程序已部署的环境?
【问题讨论】:
标签: spring-boot logback
这取决于您将如何部署应用程序。例如,如果您将其部署在服务器上,则可以通过此处的外部配置启动 Spring Boot 应用程序 -> http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
或者,如果您尝试在本地执行此操作,例如在 IntelliJ 上,您可以创建一个新配置并根据需要覆盖 Spring Boot 参数 -> https://www.jetbrains.com/help/idea/2016.2/run-debug-configuration-spring-boot.html#d687672e16
如果你使用的是 eclipse (STS) -> https://spring.io/blog/2015/03/18/spring-boot-support-in-spring-tool-suite-3-6-4
更好的是创建多个属性(或 yaml)文件,例如 application-dev.properties、application-int.properties 等,当您启动应用程序时,将配置文件设置为“dev”或“int”或无论您需要什么 -> http://docs.spring.io/autorepo/docs/spring-boot/current/reference/html/boot-features-profiles.html
【讨论】: