Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ... {
like image 354
Alexander Taylor Avatar asked Nov 20 '14 00:11

Alexander Taylor


1 Answers

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

like image 129
Alexander Taylor Avatar answered Nov 03 '22 16:11

Alexander Taylor