Reading a resource file in Spring boot

Some applications store XML files in src/main/resources folder and want to access it from a java class, using the following syntax
  InputStream ioStream = Application.class.getResourceAsStream("template.xml");
But it returns a null object.
The problem with spring boot webapp is the file is actually a classpath resource. To access it use the following syntax

InputStream ioStream = Application.class.getClassLoader().getResourceAsStream("template.xml");

Comments

Popular posts from this blog

NSSM service eats 100% CPU

JPA Vs SpringJDBC

Ignite Running in Static IP multicast mode