我有 application.properties
变量用于设置默认值:
openvasmd.socket=/usr/local/var/run/openvasmd.sock
我希望能够在应用程序运行时更改它,如下所示:
java -jar -Dopenvasmd.socket=/var/run/openvasmd.sock application.jar
但是当我想使用它的值时:
@Value("${openvasmd.socket}")
private String socket;
public String test() {
return "gvm-cli --socketpath "+socket;
}
结果是:
gvm-cli null
有人可以提示我哪里做错了吗?
最佳答案
来自https://www.baeldung.com/properties-with-spring
Properties from Command Line Arguments
As opposed to using files, properties can be passed directly on the command line:
java -jar app.jar --property="value"
You can also do this via system properties, which are provided before the -jar command rather than after it:
java -Dproperty.name="value" -jar app.jar
关于java - Spring Boot 使用 CLI arg 覆盖应用程序属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56194166/