SpringBoot-logback.xml 从应用程序读取-Environment.properties

SpringBoot- logback.xml read from application-Environment.properties

我正在使用 spring 启动应用程序。我将我的代码部署到三个不同的环境(本地、开发、集成)。当前 logback.xml 从 application.properties 读取。我如何让它从 application-dev.properties、application-int.properties.. 读取,具体取决于应用程序已部署的环境?

这取决于您将如何部署应用程序。例如,如果您将其部署在服务器上,则可以通过此处的外部配置启动 spring 启动应用程序 -> 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 引导参数 -> 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