Custom configuration files - Play! Framework 2.0

travega picture travega · May 1, 2012 · Viewed 13.5k times · Source

I have a question about loading properties from custom configuration files. I have tried two different approaches to loading my oauth.properties file but I can't get either to work so I'm hoping someone here can help me.

The first approach I tried was to add the file to the conf directory and reference it thusly:

String oauthPropertiesFile = ClassLoader.getSystemResource("oauth.properties").getFile();

But that just returned NULL.

The second approach I tries was to add:

@include.oauthProperties = oauth.properties

to the application.conf file and then reference it in my controller like:

String clientId = oauthProperties.clientId;

However this doesn't compile.

Can anyone shed some light on what I'm doing wrong here?

Answer

Victor Sergienko picture Victor Sergienko · Aug 8, 2012

What worked for me with a file in /conf:

import com.typesafe.config.ConfigFactory

val myConfig = ConfigFactory.load("myfile.properties").getConfig("my.config.prefix")