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
有效。。。