Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example
- import org.springframework.beans.factory.annotation.Autowired
- import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
- import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
- import org.springframework.context.annotation.Bean
- import org.springframework.context.annotation.Configuration
- import org.springframework.context.annotation.Profile
- import java.net.URI
- import java.net.URISyntaxException
- import javax.sql.DataSource
- @Profile("heroku")
- @Configuration
- open class HerokuConfig(@Autowired val properties: DataSourceProperties) {
- @Bean
- @Throws(URISyntaxException::class)
- open fun dataSource(): DataSource {
- val dbUri = URI(System.getenv("DATABASE_URL"))
- val url = "jdbc:postgresql://" + dbUri.host + ":" + dbUri.port + dbUri.path
- val username = dbUri.userInfo.split(":")[0]
- val password = dbUri.userInfo.split(":")[1]
- return DataSourceBuilder
- .create(this.properties.classLoader)
- .url(url)
- .username(username)
- .password(password).build()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement