Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Compile Static
- class PostgresConfig {
- String user
- String password
- String serverName
- String databaseName
- Integer portNumber
- }
- @CompileStatic
- class PostgresModule extends ConfigurableModule<PostgresConfig> {
- @Override
- protected void configure() {
- }
- @Provides
- DataSource dataSource(final PostgresConfig config) {
- createDataSource(config)
- }
- protected DataSource createDataSource(final PostgresConfig config) {
- new PgSimpleDataSource(
- user: config.user,
- password: config.password,
- serverName: config.serverName,
- databaseName: config.databaseName,
- portNumber: config.portNumber
- )
- }
- }
- ratpack {
- serverConfig {
- props([
- 'postgres.user': 'username',
- 'postgres.password': 'password',
- 'postgres.serverName': 'localhost',
- 'postgres.databaseName': 'postgres',
- 'postgres.portNumber': 5432
- ] as Map<String, String>)
- yaml "config.yaml"
- env()
- sysProps()
- require("/postgres", PostgresConfig)
- }
- bindings {
- PostgresConfig postgresConfig
- module HikariModule, { HikariConfig config ->
- config.dataSource = new PostgresModule().dataSource(postgresConfig)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement