简体   繁体   English

如何从 .properties 文件中读取系统属性

[英]How to read system properties from .properties file

I have a JAVA web application which runs on Tomcat Server.我有一个在 Tomcat 服务器上运行的 JAVA Web 应用程序。 I have a setup a property in my tomcat's VM arguments;我在我的 tomcat 的 VM 参数中设置了一个属性; something like -Denvironment =“E1”.类似于 -Denvironment =“E1”。

I want to read that property inside my app.properties file, I tried mutiple options like ${environment} and {sys:environment} but could not able to read the value.我想在我的 app.properties 文件中读取该属性,我尝试了多个选项,如 ${environment} 和 {sys:environment} 但无法读取该值。

Please help, thanks in advance.请帮忙,提前致谢。

你也可以试试这个:

${sys:environment}

It all depends on the class you are using to load your properties, because Java dont support this.这完全取决于您用来加载属性的类,因为 Java 不支持这一点。

If you try with如果你尝试

${sys:environment} ${系统:环境}

You should use Commons-Configuration您应该使用 Commons-Configuration

http://commons.apache.org/proper/commons-configuration/ http://commons.apache.org/proper/commons-configuration/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM