Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Kotlin-System.getProperty无法解析命令行参数_Spring_Kotlin - Fatal编程技术网

Spring Kotlin-System.getProperty无法解析命令行参数

Spring Kotlin-System.getProperty无法解析命令行参数,spring,kotlin,Spring,Kotlin,我有一些代码要动态加载应用程序。属性: fun loadDefaultProperties(): Properties { val configPath = System.getProperty("spring.config.location") val resource = FileSystemResource(configPath) return PropertiesLoaderUtils.loadProperties(resource) } 但是当我运行命令时 j

我有一些代码要动态加载
应用程序。属性

fun loadDefaultProperties(): Properties {
    val configPath = System.getProperty("spring.config.location")
    val resource = FileSystemResource(configPath)
    return PropertiesLoaderUtils.loadProperties(resource)
}
但是当我运行命令时

java -jar my.jar -Dspring.config.location=my/location/application.properties
System.getProperty(“spring.config.location”)
返回
null
,因此,我得到了一个
IllegalArgumentException
,因为路径是
null

为什么我无法从命令行读取参数?

您不需要引号吗

java -jar my.jar -Dspring.config.location="my/location/application.properties"

你按错误的顺序传递它们。像这样传递它们:

java "-Dspring.config.location=my/location/application.properties" -jar my.jar 
否则它们就是程序参数。我刚刚在MacOS上测试了它,上面的和

java -Dspring.config.location=my/location/application.properties -jar my.jar 

(不带引号)工作。

您不一定需要引号
-DpropertyKey=value
应该足够了,除非值中有空格或其他特殊符号…按照顺序我得到
错误:找不到或加载main class.config.location=my/location/application.properties
尝试将它们放在引号中,具体取决于您的操作系统。我刚刚在本地尝试过,效果很好。不知道为什么这被否决了。第二个选择对我不起作用。第一个是。使用Powershell,只有引号中的系统属性对我有效,例如
java“-Dspring.config.location=test”-jar some.jar
有效。。。