Check config before starting server

22 views
Skip to first unread message

ron

unread,
Feb 15, 2017, 12:00:49 PM2/15/17
to Play Framework
Is there an accepted method to test whether certain key/values have been defined in the config file, and if a value is missing, not start the server? 

ron

unread,
Feb 15, 2017, 1:31:02 PM2/15/17
to Play Framework
My solution looks like this at the moment. Let me know if there is a better way.. 

@Override
boolean validateConfig() {
String config_key = config.getString(SOME_KEY);

if(StringUtils.isEmpty(config_key)) {
throw new PlayException("Configuration error", "Could not find " + SOME_KEY + " in settings");
}

return true;
}

Will Sargent

unread,
Feb 15, 2017, 1:39:06 PM2/15/17
to play-fr...@googlegroups.com
If you call out to the underlying Typesafe Config object, then calling an undefined key will result in an exception.

--
Will Sargent
Engineer, Lightbend, Inc.


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/5379fe99-10fd-4508-9e54-7136bc924c19%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ron

unread,
Feb 15, 2017, 1:47:43 PM2/15/17
to Play Framework
I don't see this behaviour in 2.5.10 at the moment. Perhaps its a bug. 


On Wednesday, 15 February 2017 18:39:06 UTC, Will Sargent wrote:
If you call out to the underlying Typesafe Config object, then calling an undefined key will result in an exception.

--
Will Sargent
Engineer, Lightbend, Inc.


On Wed, Feb 15, 2017 at 10:31 AM, ron <rauna...@gmail.com> wrote:
My solution looks like this at the moment. Let me know if there is a better way.. 

@Override
boolean validateConfig() {
String config_key = config.getString(SOME_KEY);

if(StringUtils.isEmpty(config_key)) {
throw new PlayException("Configuration error", "Could not find " + SOME_KEY + " in settings");
}

return true;
}

On Wednesday, 15 February 2017 17:00:49 UTC, ron wrote:
Is there an accepted method to test whether certain key/values have been defined in the config file, and if a value is missing, not start the server? 

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

Will Sargent

unread,
Feb 15, 2017, 7:05:58 PM2/15/17
to play-fr...@googlegroups.com
You want the underlying Typesafe Config object, which is com.typesafe.config.Config.  You get it from configuration.underlying().


The Typesafe Config object does not return defaults:


--
Will Sargent
Engineer, Lightbend, Inc.


To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/32869302-31d4-44ab-b726-d76834267c8f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages