Skip to content

Instantly share code, notes, and snippets.

@lynas
Created September 5, 2024 10:27
Show Gist options
  • Save lynas/59d5adbc4592a05f49deffff44a0f58d to your computer and use it in GitHub Desktop.
Save lynas/59d5adbc4592a05f49deffff44a0f58d to your computer and use it in GitHub Desktop.
Read value from application.yml as map

application.yml

app:
  vendor:
    port:
      ABL: 8300
      MENEKIS: 5050

Spring

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties("app.vendor")
data class VendorConfig(
    private val port: Map<String, Int>
) {
    fun getInterfacePort(vendorName: String): Int {
        return port[vendorName] ?: 80
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment