Hi,
I'm looking for general advice as to how I should implement global config variables in a webapp.
At the moment I create a singleton object at startup (done in ServletContextListener.contextInitialized()...). My singleton reads a config file and stores the values in variables. I used a singleton to make sure that there are no multiple copies of the global config variables.
I did not manage to code a singleton
java bean so my singleton class object is just an attribute stored in ServletContext. Is it possible/sensible to create a java bean as a singleton class?
Now I see 2 alternatives:
1)
Use scripting to get the values out of the singleton e.g:
The problem with this is, I understand one should use Expression Language today and not scriptlets?
2)
Create a normal java bean and store it in ServletContext. This approach would rely on the principle that nobody creates new instances of the bean. This would not be a problem in our organisation but somehow this solution feels like a compromise to me.
Or am I completely lost here. Is there a common way how this should be done. None of my books really address this and I have not been able to find much on the internet. Is the simple java bean approach an accepted solution or would it be considered bad style? For our new application I would like to get this basic principle right from the start.
Cheers
Keimo