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?
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());
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()
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.