@PropertySource with absolute path to avoid "java.io.FileNotFoundException: Could not open ServletContext resource"

5.4k Views Asked by At

My application gets the location of a properties file from an environment variable, and it may not be in the WEB-INF folder. I'm getting file not found, but this file definitely exists already. I don't want to use the classpath: prefix, and I don't want it to be relative to the app root.

@PropertySource("${propfile}")
public class ... {
1

There are 1 best solutions below

0
On

To use an absolute path, try file: at the beginning.

@PropertySource("file:${propfile}")

source: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html