No configuration setting found for key typesafe config

MIkCode picture MIkCode · Jan 15, 2015 · Viewed 57.9k times · Source

Im trying to implement a configuration tool typesafehub/config im using this code

 val conf = ConfigFactory.load()
 val url = conf.getString("add.prefix") + id + "/?" + conf.getString("add.token")

And the location of the property file is /src/main/resources/application.conf

But for some reason i'm receiving

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'add'

File content

add {
  token = "access_token=6235uhC9kG05ulDtG8DJDA"
  prefix = "https://graph.facebook.com/v2.2/"
  limit = "&limit=250"
  comments="?pretty=0&limit=250&access_token=69kG05ulDtG8DJDA&filter=stream"
  feed="/feed?limit=200&access_token=623501EuhC9kG05ulDtG8DJDA&pretty=0"
}

Everything looks configured correctly ?? do i missed something .

thanks,

miki

Answer

Reid Spencer picture Reid Spencer · Jan 16, 2015

The error message is telling you that whatever configuration got read, it didn't include a top level setting named add. The ConfigFactory.load function will attempt to load the configuration from a variety of places. By default it will look for a file named application with a suffix of .conf or .json. It looks for that file as a Java resource on your class path. However, various system properties will override this default behavior.

So, it is likely that what you missed is one of these:

  • Is it possible that src/main/resources is not on your class path?
  • Are the config.file, config.resource or config.url properties set?
  • Is your application.conf file empty?
  • Do you have an application.conf that would be found earlier in your class path?
  • Is the key: add defined in the application.conf?