1

I have a webapplication on Java spring. I need to read application specific settings when the application will be initialized. I have added app.properties under WebContent/WEB-INF but I am not able to get that file from the class. If I provide InputStream input = servletContext.getResourceAsStream("WEB-INF/spring.properties"); prop.load(input);

then it is showing file is not present. I can not use absolute path. What will be the path?

user3306669
  • 117
  • 1
  • 11

1 Answers1

3

From the Javadoc ServletContext.getResource:

The path must begin with a / and is interpreted as relative to the current context root, or relative to the /META-INF/resources directory of a JAR file inside the web application's /WEB-INF/lib directory.

Therefore try

InputStream in = servletContext.getResourceAsStream("/WEB-INF/<filename>");
wero
  • 32,544
  • 3
  • 59
  • 84