无法打开java@PropertySource,因为它不存在
我的配置文件存在问题,它位于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\
日志中出现以下错误:属性位置
Properties location [${ext.properties.dir:classpath:}/properties.properties] not resolvable: class path resource [properties.properties] cannot be opened because it does not exist
如何修复此错误
# 1 楼答案
Spring Boot在类路径上查找
application.properties
。您不需要显式的@PropertySource
注释。而且@PropertySource
没有能力解析路径中的SPEL,从您收到的错误消息中可以明显看出这一点使用
src/main/resources/application.properties
。当你想使用外部文件时,可以使用spring.config.location
,比如他在回答中建议的@juan-calvopina-m# 2 楼答案
我看到您正在使用
spring boot
应用程序,根据spring documentation您可以尝试使用这个环境属性:最后的指示是: