General suggestion about Singletons: avoid them ;) Why? They are usually hard to test and hard to identify who is calling/depends-on your singleton, bc you add a global/static dependency somewhere.
Instead of singleton, you can let Guice to handle the lifecycle of that object as singleton. For example, here is a high level usage of what you should do:
{
bind(Database.class -> new Database());
onStart(registry -> {
Config conf = registry.require(Config.class);
Database db = registry.require(Database.class);
db.init(conf.getString("db.url"), conf.getString("db.user", conf.getString("db.password"));
});
}
That is what you need to create a singleton in Guice and start/initialize.
Clients of database looks like:
{
get("/db", req -> {
Database db = req.require(Database.class);
// ....
});
}
Or from mvc route:
public class Controller {
@Inject
public Controller(Database db) {
// ...
}
}
Client/dependency of your singleton are clearly identifiable and testable (specially the mvc route).
Did you try jooby jdbc-module? Is there a bug there with postgreSQL?
Thanks