Reading nested JSON into Spring config bean from K8S ConfigMap File

10/18/2020

We have a enterprise Kubernetes setup on which I am deploying a spring boot application

The service injects configMap as a json file at the location - /etc/config/appConfig.json

The JSON File looks like

{
    "configResolution": {
      "resolved": {
        "groupid": "listener-consumerGrp",
        "topic": "Product"
      }
    }
 }

I am trying to read the K-V pairs to variables in spring boot

String groupid;
String topic

Need assistance on how to read using Spring Cloud Kubernetes, with refresh of 15 min

Here is the application.yml , I used

spring:
  profiles: dev
  cloud:
    kubernetes:
      config:
        name: PLACEHOLDER-LISTENER
        namespace: team924
        enable-api: false
        paths:
          -/etc/config/appConfig.json
      reload:
        enabled: true
        mode: polling
        period: 150000

Any help is appreciated

-- Sandeep540
config
java
kubernetes
spring-boot

0 Answers