CurrentHikariModule
在 Java 代码中包含硬编码的值,这不是一个好习惯,最好使用db.properties
. 如何做到这一点?我需要创建一个自定义ConfigurableModule<MyModule.Settings>
并HikariModule
在里面注册MyModule
吗?我还没有找到如何在模块中注册模块的方法。谢谢!
public class App {
public static void main(String[] args) throws Exception {
RatpackServer.start(s -> s
.serverConfig( configBuilder -> configBuilder
.findBaseDir()
.props("db.properties")
.require("/database", Settings.class)
)
.registry(Guice.registry( bindings -> bindings
.module(HikariModule.class, hm -> {
hm.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
hm.addDataSourceProperty("url", "jdbc:postgresql://localhost:5433/ratpack");
hm.setUsername("postgres");
hm.setPassword("postgres");
}).bind(DatabaseInit.class)
))
.handlers( chain -> chain
...
)
);
}
}