'How to add classpath resource in application.yml file
With spring-boot, in case of application.properties file there is provision to specify classpath in value.
app.templates = classpath:app\mock-templates
How to specify same thing inside application.yml?
When specified like this, value read is not correct -
app:
templates : 'classpath:app\mock-templates'
Value injection -
@Value("${app.templates}")
private String templateLocation;
// value injected is "classpath:app\mock-templates", it should be <absolute-path>\app\mock-templates
Solution 1:[1]
I just check that no matter if you use .properties
or .yaml
file you will have always classpath:app\mock-templates
as an injected property value. And that's ok. Spring does not complete classpath:
prefix to the real path in a time of reading from properties. That will be done next by ClassPathResource.
P.S. I think quotest also don't make any sense here.
Solution 2:[2]
I faced the exact same issue and there is a way to solve this. I tried using classpath
but it does not work. Then I used this way
app:
templates: "${PWD}/your/resources/dir/location"
In your application.yml
file. It works for me just make sure your PWD
will come from the path where your test are running. If you are using git hooks
for running tests then mostly it's run from project root dir.
Solution 3:[3]
Was able to get this working by mentioning
src/test/resources/<file_name>
in application.yml
truststore: src/test/resources/trust.jks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | RAVI SINGH |
Solution 3 | Pradeep S |