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

My application gets the location of the properties file from an environment variable and may not be in the WEB-INF folder. I get the file was not found, but this file definitely exists. I do not want to use the classpath: prefix, and I do not want it to be relative to the root of the application.

 @PropertySource("${propfile}") public class ... { 
+5
source share
1 answer

To use the 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

+9
source

Source: https://habr.com/ru/post/1207267/


All Articles