Issue
I have a maven Spring project, there is xml
file inside src/main/resources/xyz.xml
. How can I read it inside spring MVC controller.
I am using
InputStream is = getClass().getResourceAsStream("classpath:xyz.xml");
but is
is null
.
Solution
Resource resource = new ClassPathResource(fileLocationInClasspath);
InputStream resourceInputStream = resource.getInputStream();
using ClassPathResource and interface resource. But make sure you are copying the resources directory correctly (using maven), and its not missing, for example if running tests as part of test context.
Answered By - NimChimpsky
Answer Checked By - Gilberto Lyons (JavaFixing Admin)