Search code examples
javaplayframeworkplayframework-2.0typesafe-config

Play Framework - How to keep the configurations of my module inside it?


I am using Play Framework 2.2.x/Java.

I want to create a module to sperate some of the logics from my main application and also I want to use the application.conf inside the module for its configurations instead of using the main application's config file!

But using the following snippet in the module, only reads values from the main application config file:

Play.application().configuration().getString("myVar");

Is there any other way to get the values from the application.conf file inside my module?


Solution

  • Play uses the typesafe-config library for reading configuration. This is actually a Java library, even though Typesafe is a Scala company.

    The documentation for typesafe-config says "The idea is that libraries and frameworks should ship with a reference.conf in their jar."

    So your module's config should be stored in a file called reference.conf - the format is exactly the same, it's just the name that is different.

    The problem occurs because there is a conflict between the two config files because they are named the same, so it probably goes by classpath order or something. Don't use two application.conf files - this problem has bitten me in the past!