2016-12-04 37 views
0

我正在使用spring引导应用程序。我将我的代码部署到三个不同的环境(local,dev,int)。目前,logback.xml从application.properties中读取。我如何使它从application-dev.properties,application-int.properties ..中读取,取决于应用程序已部署的环境?SpringBoot-logback.xml从application-Environment.properties中读取

+0

请参阅spring doc:http://docs.spring.io/spring-boot/docs/current/reference /html/boot-features-logging.html –

回答

0

这取决于你将如何部署应用程序。例如,如果你在一台服务器上部署它,您可以通过外部配置启动春季启动应用程序喜欢这里 - >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,你可以创建一个新的配置,并覆盖弹簧引导参数,只要你想 - >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

+0

谢谢,我继续前进的方式是在环境变量中具有这些必要的值。看起来Spring引导logback首先查看env变量,然后查看应用程序属性文件。所以,对于每个env,我都会根据该env拥有环境变量var。 – JdGurkhe

+0

当然,我错过了,是的,环境变量也很好。 –