I have a general XML file containing different properties for my Play! application like:
- customer location of CSS file
- preffered dateTime format for user
- other specific resources that I need for my application
So when starting Play! I want to load these resource once in Play!. Once loaded they will not change. I want to avoid to load the external XML file on each request. So what I have done is the following:
Created a class that follows the singleton pattern to load the XML file.
Then created a Model that contains all my application properties that I need. This class has private properties so I instantiate this Model everywhere where I need it like:
myAppProperties = new AppProperties();
This question might be similar like questions about Globals : https://groups.google.com/forum/?fromgroups#!searchin/play-framework/global$20variables/play-framework/Q9DBAQtQWYc/OnS0e4dXAhAJ and Cross controller variables
Would love to hear some feedback.
Thanks!
The preferred way to load properties is usually via the application.conf. You can also define them in other conf file and use include. If you need to centralise all your properties define your AppProperties as:
and in your application.conf: