简体   繁体   English

如何在Java Web应用程序中为系统属性指定默认值?

[英]How can I specify a default value for a system property in a Java web app?

It seems like this should be so easy, but I have been banging my head on it for days. 似乎这应该很容易,但是我已经为此努力了好几天。

I have a simple Java web app that uses Jetty embedded in an executable jar, and I am using system properties to define configuration info that I'm keeping separated from the app. 我有一个简单的Java Web应用程序,该应用程序使用嵌入在可执行jar中的Jetty,并且正在使用系统属性来定义与应用程序保持分离的配置信息。 I like that I can set system properties on the command line with -D . 我喜欢这样,我可以在命令行上使用-D设置系统属性。 For example, 例如,

java -Dbackend=backend_url -jar ...

Is there a way to set a default value for such a system property? 有没有办法为这样的系统属性设置默认值?

If you are the one doing the reading of those properties. 如果您正在阅读这些属性。 when you read them you can specify what is their default (in case they were not given via the cmd). 阅读它们时,您可以指定它们的默认值(以防未通过cmd给出它们)。

you can read about it here: link 您可以在这里阅读有关内容: 链接

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

相关问题 如何为java应用程序指定全局系统属性? - How to specify a global system property for java applications? 如何指定嵌套属性的默认值? - How to specify the default value for nested property? 如何为appengine上的JDO实体中的字段指定默认值? - How can I specify a default value for a field in a JDO entity on appengine? 如何在 Jersey 中动态指定默认值? - How can I specify a Default value dynamically in Jersey? 如何从jersey的属性文件中指定路径值? - How can i specify path value from property file in jersey? Spring 4 @Value,其中property default是一个java系统属性 - Spring 4 @Value where property default is a java system property Ant 如何从自定义 Java 系统属性中获取值 - How can Ant get the value from custom Java system property 如何在 vscode 中设置 launch.json 中的默认 java 配置,以使 vscode 在每次运行应用程序时停止要求我指定主类? - How can I set in vscode a default java configuration in launch.json to make vscode stop asking me to specify a main class every time I run the app? 有没有一种方法可以在Spring XML中指定默认属性值? - Is there a way to specify a default property value in Spring XML? 尝试为休眠中的属性指定默认值 - Trying to specify default value for property in hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM