Java @无法打开PropertySource,因为它不存在

Java @无法打开PropertySource,因为它不存在,java,spring,Java,Spring,我的配置文件存在问题,它位于jar文件以外的其他目录中 我使用@PropertySource加载属性 @PropertySource(ignoreResourceNotFound = true, value = "${ext.properties.dir:classpath:}/properties.properties") 我尝试使用以下命令运行jar: java -jar import-0.0.1-SNAPSHOT.jar -Dext.properties.dir=file:/C:\Use

我的配置文件存在问题,它位于jar文件以外的其他目录中

我使用
@PropertySource
加载属性

@PropertySource(ignoreResourceNotFound = true, value = "${ext.properties.dir:classpath:}/properties.properties")
我尝试使用以下命令运行jar:

java -jar import-0.0.1-SNAPSHOT.jar -Dext.properties.dir=file:/C:\Users\Admin\Desktop\
日志中出现以下错误:属性位置

属性位置 [${ext.properties.dir:classpath:}/properties.properties]无法解析: 无法打开类路径资源[properties.properties],因为它 不存在


如何修复此错误?

我看到您正在使用
spring boot
应用程序,根据您可以尝试使用此环境属性:

--spring.config.location=file:/path/location/file-name.properties
最后的指示是:

java -jar import-0.0.1-SNAPSHOT.jar --spring.config.location=file:C:\Users\Admin\Desktop\import.properties

Spring Boot在类路径上查找
应用程序.properties
。您不需要显式的
@PropertySource
注释。而且
@PropertySource
无法解析路径中的SPEL,这从您收到的错误消息中可以明显看出


使用
src/main/resources/application.properties
。当你想使用外部文件时,使用
spring.config.location
就像他在回答中建议的@juan-calvopina-m一样。

这可能会帮助你-@arbit,我做了与回答中相同的配置,但是我得到了
无法打开,因为它不存在
您使用的是
spring mvc
还是
spring boot
?我使用的是
spring boot
spring.config。位置
对他没有帮助
@PropertySource
您收到了相同的错误还是不同?你查过@AbhijitSarkar的建议了吗?@JUANCALVOPINAM,谢谢,
-spring.config.location
有效well@Alex78191你的评论是否相关,具体如何?