Move locale setting code to ensure it's always set.
@@ -673,17 +673,6 @@ public class Jooby implements Router, Registry {
* @return Server.
*/
public @Nonnull Server start() {
- if (locales == null) {
- String path = "application.lang";
- locales = Optional.of(getConfig())
- .filter(c -> c.hasPath(path))
- .map(c -> c.getString(path))
- .map(v -> LocaleUtils.parseLocales(v).orElseThrow(() -> new RuntimeException(String.format(
- "Invalid value for configuration property '%s'; check the documentation of %s#parse(): %s",
- path, Locale.LanguageRange.class.getName(), v))))
- .orElseGet(() -> singletonList(Locale.getDefault()));
- }
-
List<Server> servers = stream(
spliteratorUnknownSize(
ServiceLoader.load(Server.class).iterator(),
@@ -737,6 +726,17 @@ public class Jooby implements Router, Registry {
mode = ExecutionMode.DEFAULT;
}
+ if (locales == null) {
+ String path = "application.lang";
+ locales = Optional.of(getConfig())
+ .filter(c -> c.hasPath(path))
+ .map(c -> c.getString(path))
+ .map(v -> LocaleUtils.parseLocales(v).orElseThrow(() -> new RuntimeException(String.format(
+ "Invalid value for configuration property '%s'; check the documentation of %s#parse(): %s",
+ path, Locale.LanguageRange.class.getName(), v))))
+ .orElseGet(() -> singletonList(Locale.getDefault()));
+ }
+
ServiceRegistry services = getServices();
services.put(Environment.class, getEnvironment());
services.put(Config.class, getConfig());
