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
...
)
);
}
}
感謝丹!尤其是鏈接。 –