Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. @Compile Static
  2. class PostgresConfig {
  3. String user
  4. String password
  5. String serverName
  6. String databaseName
  7. Integer portNumber
  8. }
  9.  
  10. @CompileStatic
  11. class PostgresModule extends ConfigurableModule<PostgresConfig> {
  12. @Override
  13. protected void configure() {
  14. }
  15.  
  16. @Provides
  17. DataSource dataSource(final PostgresConfig config) {
  18. createDataSource(config)
  19. }
  20.  
  21. protected DataSource createDataSource(final PostgresConfig config) {
  22. new PgSimpleDataSource(
  23. user: config.user,
  24. password: config.password,
  25. serverName: config.serverName,
  26. databaseName: config.databaseName,
  27. portNumber: config.portNumber
  28. )
  29. }
  30. }
  31.  
  32. ratpack {
  33. serverConfig {
  34. props([
  35. 'postgres.user': 'username',
  36. 'postgres.password': 'password',
  37. 'postgres.serverName': 'localhost',
  38. 'postgres.databaseName': 'postgres',
  39. 'postgres.portNumber': 5432
  40. ] as Map<String, String>)
  41. yaml "config.yaml"
  42. env()
  43. sysProps()
  44. require("/postgres", PostgresConfig)
  45. }
  46. bindings {
  47. PostgresConfig postgresConfig
  48. module HikariModule, { HikariConfig config ->
  49. config.dataSource = new PostgresModule().dataSource(postgresConfig)
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement