Reputation: 55
Akka 1.3 had the ability to look up a config variable, and it returned an option, so defaults could be specified.
Akka 2.0 does not have this. So how do I check for the existence of a variable, and specify a default if it is not defined?
Example:
In 1.3: config.getString("myvariable", "mydefault") // default specified
In 2.0: GlobalActorSystem.settings.config.getString("myvariable") //no way to specify default
Upvotes: 1
Views: 188
Reputation: 15472
You can use config.hasPath
to find out whether a setting has been specified. But I would recommend that only in the case where you want to attach special meaning to the omission of a setting. If you just want to have a default, include a reference.conf
in your project (at the root of the JAR) which contains that value.
Upvotes: 1
Reputation: 26597
You shouldn't put defaults in code, you put your defaults in a reference.conf placed in your /resources folder of your jar. Read about the Typesafe Config project here: https://github.com/typesafehub/config
Upvotes: 1