[英]override values in application.properties files from command line
I have apllication.properties files in java web application which contains these properties. 我在java web应用程序中有apllication.properties文件,其中包含这些属性。
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:19095/test
spring.datasource.username=test
spring.datasource.password=test123
But I want to override these properties (except driverClassName) while starting tomcat server. 但我想在启动tomcat服务器时覆盖这些属性(driverClassName除外)。 I'm trying to set these variables from command line, but it's not working. 我试图从命令行设置这些变量,但它不起作用。
tomcat version : 7.0.63 tomcat版本:7.0.63
Why don't you use a property placeholder with config directory specified by a system parameter: 为什么不使用带有系统参数指定的config目录的属性占位符:
<context:property-placeholder location="file:${configLocation}/database.properties:defaultDatabase.properties" />
Then start the tomcat with: 然后启动tomcat:
-DconfigLocation=/opt/config
see http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html and also Loading property file from system properties with default path in Spring context 请参阅http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html以及使用Spring上下文中的默认路径从系统属性加载属性文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.