Skip to content

Commit

Permalink
Fix for #613 when driver class is missing from config
Browse files Browse the repository at this point in the history
When using h2 or postgres as storage, Reaper will expect a driver class to be passed and a classloader failure triggers if it's missing. This patch enforces the DriverClass if it's missing for both h2 and postgres and avoid the exception.
  • Loading branch information
adejanovski committed Feb 15, 2019
1 parent 4c225e6 commit 0a2c11f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
import io.prometheus.client.exporter.MetricsServlet;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.flywaydb.core.Flyway;
Expand Down Expand Up @@ -332,7 +333,13 @@ private IStorage initializeStorage(ReaperApplicationConfiguration config, Enviro
|| "database".equalsIgnoreCase(config.getStorageType())) {
// create DBI instance
final DBIFactory factory = new DBIFactory();

if (StringUtils.isEmpty(config.getDataSourceFactory().getDriverClass())
&& "postgres".equalsIgnoreCase(config.getStorageType())) {
config.getDataSourceFactory().setDriverClass("org.postgresql.Driver");
} else if (StringUtils.isEmpty(config.getDataSourceFactory().getDriverClass())
&& "h2".equalsIgnoreCase(config.getStorageType())) {
config.getDataSourceFactory().setDriverClass("org.h2.Driver");
}
// instanciate store
storage = new PostgresStorage(factory.build(environment, config.getDataSourceFactory(), "postgresql"));
initDatabase(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jmxCredentials:

# database section will be ignored if storageType is set to "memory"
postgres:
driverClass: org.postgresql.Driver
user: postgres
password:
url: jdbc:postgresql://127.0.0.1/reaper
Expand Down

0 comments on commit 0a2c11f

Please sign in to comment.