简体   繁体   English

从命令行覆盖application.properties文件中的值

[英]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.

相关问题 mvn test - 覆盖 application.properties 中的值 - mvn test - override values in application.properties 寻找一种在应用程序运行时覆盖 application.properties 值的方法 - Looking for a way to override application.properties values during application runtime 子应用程序中的application.properties文件不会覆盖主应用程序中的application.properties文件 - application.properties file from child application not override application.properties file in main application 覆盖application.properties中的值 - Override value in application.properties 使用application.properties中的值初始化过滤器 - Initializing filter with values from application.properties 通过命令行选择application.properties文件 - Choose application.properties file via command line 将 gradle 命令行 arguments 传递给 application.properties - Pass gradle command line arguments to application.properties 如何从 Java Spring 项目中的 application.properties 以外的配置文件中获取值 - How to pick up values from config files other than application.properties in Java Spring project 将 application.properties 中的默认值设置为 @Entity - Set default values from application.properties to an @Entity Spring 配置文件未从 application.properties 读取值 - Spring Configuration file not reading values from application.properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM