0
当前HikariModule
包含Java代码中的硬编码值,这不是一种好的做法,要好得多使用在db.properties
中定义的值。如何实现这一目标?我是否需要在MyModule
内部创建自定义ConfigurableModule<MyModule.Settings>
并注册HikariModule
?我还没有找到如何在模块内注册模块的方法。谢谢!如何使用应用程序配置注册Ratpack的ConfigurableModule
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
...
)
);
}
}
感谢丹!尤其是链接。 –