Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package com.example
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired
  4. import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
  5. import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
  6. import org.springframework.context.annotation.Bean
  7. import org.springframework.context.annotation.Configuration
  8. import org.springframework.context.annotation.Profile
  9. import java.net.URI
  10. import java.net.URISyntaxException
  11. import javax.sql.DataSource
  12.  
  13. @Profile("heroku")
  14. @Configuration
  15. open class HerokuConfig(@Autowired val properties: DataSourceProperties) {
  16. @Bean
  17. @Throws(URISyntaxException::class)
  18. open fun dataSource(): DataSource {
  19. val dbUri = URI(System.getenv("DATABASE_URL"))
  20. val url = "jdbc:postgresql://" + dbUri.host + ":" + dbUri.port + dbUri.path
  21. val username = dbUri.userInfo.split(":")[0]
  22. val password = dbUri.userInfo.split(":")[1]
  23.  
  24. return DataSourceBuilder
  25. .create(this.properties.classLoader)
  26. .url(url)
  27. .username(username)
  28. .password(password).build()
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement