Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No configuration setting found for key typesafe config

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

like image 573
MIkCode Avatar asked Jan 15 '15 20:01

MIkCode


People also ask

What is Typesafe config?

Overview. Recently I discovered an awesome Java library about configuration — Typesafe Config (GitHub). It supports Java properties, JSON and a human-friendly JSON superset. It can load resources from different places: files, URLs, classpath. It supports types, loading convention, substitutions, properties merging, etc ...

What is application conf file?

An application configuration file is an XML file used to control assembly binding. It can redirect an application from using one version of a side-by-side assembly to another version of the same assembly. This is called per-application configuration.


2 Answers

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?
like image 132
Reid Spencer Avatar answered Sep 20 '22 07:09

Reid Spencer


Are you using an IDE or sbt? I had a similar problem while using Eclipse. It simply did not find the application.conf file at first and later on failed to notice edits. However, once I ran my program via sbt, all worked just fine, including Eclipse. So, I added 'main/resources' to the libraries (Project -> Properties -> Java Build Path -> Libraries", "add class folder"). That might help you as well.

like image 33
Tim Malt Avatar answered Sep 22 '22 07:09

Tim Malt