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 {


   // 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 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();


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

2 answers

can you try putting your properties directly in the src folder instead of the WEB-INF folder?

| | +  
| -




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:



All Articles