Home > Software design >  How to set dynamic value in springboot for connecting to mysql?
How to set dynamic value in springboot for connecting to mysql?

Time:01-13

Currently, I have this in my springboot application.dev.yaml:

datasource:
    url: jdbc:mysql://mysql/$DB_HOST?useSSL=false&allowPublicKeyRetrieval=true
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver

I want to add a dynamic value in username, passwords, $DB_HOST field so that it can pick those values from the secrets file in Kubernetes. The secrets file in Kubernetes is encrypted with base64

CodePudding user response:

In Spring Boot, any property can be overridden by an environment variable of the same name, with the characters changed to upper case, and the dots changed to underscores.

For example datasource.url can be overridden by setting an environment variable like DATASOURCE_URL, which you define in Kubernetes

Source: https://developers.redhat.com/blog/2017/10/04/configuring-spring-boot-kubernetes-secrets#setup

  • Related