Reputation: 1681
I have the problem with configuration file that is located in other directory than my jar file.
I use @PropertySource
for loading properties.
@PropertySource(ignoreResourceNotFound = true, value = "${ext.properties.dir:classpath:}/properties.properties")
I try to run jar using following command:
java -jar import-0.0.1-SNAPSHOT.jar -Dext.properties.dir=file:/C:\Users\Admin\Desktop\
The following error pring in logs: Properties location
Properties location [${ext.properties.dir:classpath:}/properties.properties] not resolvable: class path resource [properties.properties] cannot be opened because it does not exist
How can I fix this error?
Upvotes: 2
Views: 5315
Reputation: 24568
Spring Boot looks for application.properties
on classpath. You don't need an explicit @PropertySource
annotation. And @PropertySource
doesn't have the capability to resolve SPEL in the path, which should be evident from the error message you're getting.
Use src/main/resources/application.properties
. When you want to use the external file, use spring.config.location
like @juan-calvopina-m suggested in his answer.
Upvotes: 0
Reputation: 3965
I saw that you are using spring boot
application, according to the spring documentation you can try to use this environment property:
--spring.config.location=file:/path/location/file-name.properties
The final instruction would be:
java -jar import-0.0.1-SNAPSHOT.jar --spring.config.location=file:C:\Users\Admin\Desktop\import.properties
Upvotes: 1