You cannot use this keyword as -
props.load(this.getClass().getResourceAsStream("myProps.properties"));
in a static context.
It would be best to get the application context, for example -
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/META-INF/spring/app-context.xml");
then you can load the resource file from the class path -
//load a properties file from class path, inside static method prop.load(context.getClassLoader().getResourceAsStream("config.properties"));
This will work for both static and non-static contexts, and the best part of this properties file can be in any package / folder included in the application class path.
Mukus Dec 02 2018-12-12T00: 00Z
source share