Read Properties File in Spring with Kotlin

import java.io.FileInputStream
import java.util.Properties
import org.springframework.util.ResourceUtils

object Configuration {
    private val properties: Properties = Properties()

    val databaseHost: String?
    val databaseName: String?
    val databaseUser: String?
    val databasePassword: String?
    val securitySecret: String

    init {
        val file = ResourceUtils.getFile("classpath:app.properties")
        val stream = FileInputStream(file)
        properties.load(stream)
        databaseHost = properties.getProperty("database.host")
        databaseName = properties.getProperty("database.name")
        databaseUser = properties.getProperty("database.user")
        databasePassword = properties.getProperty("database.password")
        securitySecret = properties.getProperty("security.secret")!!
    }
}

Leave a Reply

Your email address will not be published.