How to load properties file and pass it to java singleton (enum)
I have a unicast java class that has my application settings.
I used this approach: What is an efficient way to implement singleton pattern in Java?
So, I have a:
public enum MySettings {
INSTANCE;
// bunch of private vars
private MySettings {
// load a json file and set my properties
JsonParser parser = jf.createJsonParser(new File("HARD_CODED_PATH_HERE"));
}
// public getters/setters here
}
So the problem is with the hardcoded path I have.
I created a settings.properties file in / WEB -INF / folder, now the problem is the only way to know how to load the properties file, it needs the servlet context:
Properties prop = new Properties();
propertiesload(getServletContext().....);
Is there any other way to download this?
So this properties file is a static view of the properties file? that is, is it very fast and efficient?
source to share
Spring has the ability to render property files as beans. You can take this route, given that you have marked the "Spring" message.
Here's one guy tackling loading properties files with Spring:
http://www.zparacha.com/how-to-read-properties-file-in-spring/#.T2JQqt5SRfQ
source to share