Reputation: 16982
I have a Spring Boot App. I am trying to read few files that I have placed under main/resources folder. I see that Spring Boot automatically reads application.properties under resources folder. However it doesn't seem to read other xml / text files that I have placed under resources folder.
Source xslt = new StreamSource(new File("removeNs.xslt"));
Should I add any additional configuration for the program to automatically read all the files under resources folder without having to explicitly provide the path?
Upvotes: 0
Views: 1557
Reputation: 17268
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("removeNs.xslt").getFile());
This should work.
Thanks @Edwin for mentioning a more robust solution:
File file = new File(Thread.currentThread().getContextClassLoader().getResource("removeNs.xslt").getFile());
Upvotes: 4
Reputation: 2650
You need to specify that you want to read specific files under resources folder using
@PropertySource
annotation.
you can specify multiple property sources using
@PropertySources({
@PropertySource(),
@PropertySource()
})
Upvotes: 1