From 769416294c21374569cfcf8bcf6faa534a01ad5e Mon Sep 17 00:00:00 2001 From: Michael Hertig Date: Tue, 3 Oct 2023 15:04:48 +0200 Subject: [PATCH] Skip ServerConfig creation for datasources missing db config, closes #402 (cherry picked from commit 443b970efbc8e723abe72ef6713a98ae20d62a8d) --- .../src/main/java/play/db/ebean/DefaultEbeanConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java index bddf5a66..8e91d061 100644 --- a/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java +++ b/play-ebean/src/main/java/play/db/ebean/DefaultEbeanConfig.java @@ -18,6 +18,7 @@ import org.reflections.util.ConfigurationBuilder; import org.reflections.util.FilterBuilder; import play.Environment; +import play.Logger; import play.db.DBApi; /** Ebean server configuration. */ @@ -49,6 +50,8 @@ public static class EbeanConfigParser implements Provider { private final Environment environment; private final DBApi dbApi; + private static final Logger.ALogger LOGGER = Logger.of(DefaultEbeanConfig.class); + @Inject public EbeanConfigParser(Config config, Environment environment, DBApi dbApi) { this.config = config; @@ -75,6 +78,12 @@ public EbeanConfig parse() { for (Map.Entry> entry : ebeanConfig.getDatasourceModels().entrySet()) { String key = entry.getKey(); + if (dbApi.getDatabase(key) == null) { + LOGGER.debug("There is an 'ebean.{}' but no 'db.{}' configuration", key, key); + LOGGER.info("Skipping connection for datasource '{}'", key); + continue; + } + DatabaseConfig serverConfig = new DatabaseConfig(); serverConfig.setName(key); serverConfig.loadFromProperties();