title: Consume k8s configmap in spring
body: <p>I've got a spring boot service that presently uses <code>.properties</code> file for consuming variables using the spring @Value annotation. Recently we have been migrating the spring boot service to K8 cluster. This means that, we need to create a <code>configmap.yml</code> file containing all the same properties as the <code>.properties</code> file. And whenever changes to properties are made, it must be done in both places, the configmap and <code>.properties</code> file used for local dev. So we have to manage 2 files (configmap and .properties) for each spring profile. Is there a better way to do this? We use gitlab ci/cd tools for deployment.</p>
  
  <p>Is there a way to use the configmap instead of the properties for local development in our machines, so that we can discard the .properties file altogether and only maintain configmap? </p>
  
  <p>What's the ideal way to manage properties for the spring boot application?</p>
  
  <p>Sample service-config-map.yaml</p>
  
  <pre class="lang-yaml prettyprint-override"><code>kind: ConfigMap 
  apiVersion: v1 
  metadata:
    name: myservice-config
  data:
    server.port: "10300"
    spring.application.name: myserviceGateway
    myservice.application.name: helloworld
    myservice.server.apiContext: /api
    myservice.server.versionContext: /v
    myservice.current.version=2.0
  
  </code></pre>
  
  <p>properties file <code>application.properties</code></p>
  
  <pre><code>server.port=10300
  spring.application.name=myserviceGateway
  myservice.application.name=helloworld
  myservice.server.apiContext=/api
  myservice.server.versionContext=/v
  myservice.current.version=2.0
  </code></pre>