ZYVOPMulti-Platform Sync
SeriesAI NewsWhy ZyVOPJoin Discord
LoginGet Started
ZYVOPMulti-Platform Sync

The Developer Publishing Hub. Write once, publish everywhere, and make your work citation-ready with built-in SEO, AEO, and GEO discovery support. Zero reader paywalls.

Content

  • Categories
  • Tags
  • Badges
  • Leaderboard
  • Write Article
  • Newsletter

Company

  • About Us
  • Why ZyVOP
  • Changelog
  • Compare Platforms
  • Hashnode vs ZyVOP
  • DEV vs ZyVOP
  • Developer API & CLI
  • Author Handbook
  • Contact

Connect

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DMCA Policy
  • Code of Conduct

ยฉ 2026 ZyVOP. Developer Publishing Hub.

Zero paywalls ยท Full content ownership
All systems operational
HomeTutorialCentralized Secret Management with Spring Cloud Config & Vault: A Production Guide
Tutorial
Discussion

Centralized Secret Management with Spring Cloud Config & Vault: A Production Guide

How to manage environment properties and encrypted database secrets across microservices without rebuilding containers.

Shubham Bhati
Shubham Bhati
Java Backend Engineer | Microservices
August 1, 2026Updated August 21, 2026
2 min read
Series

Production-Grade Microservices Architecture with Java & Spring Boot

Part 2 of 3

PrevNext
Centralized Secret Management with Spring Cloud Config & Vault: A Production Guide
#backend#springcloud#security#springboot#java#Microservices
๐Ÿ‘1

Hardcoding DB credentials, JWT secrets or API keys inside application.yml or Docker images is a security disaster waiting to happen. Rotating a password shouldn't require rebuilding 10 microservice containers and triggering a full redeployment pipeline.

In Part 2 of our Spring Boot Microservices series, we will build a centralized configuration server using Spring Cloud Config integrated with HashiCorp Vault for secret encryption.


๐Ÿ” Why Centralized Configuration Management?

In microservices architectures, centralized config management solves three critical challenges:

  1. Zero-Downtime Secret Rotation: Change database passwords or API keys in Vault without restarting microservices.

  2. Environment Isolation: Maintain separate profile configurations (dev, staging, prod) in a single Git or Vault backend.

  3. Audit Logging: Every secret read or modification is logged with timestamps and identity tokens.


๐Ÿ› ๏ธ Step 1: Setting Up the Spring Cloud Config Server

Create a standalone Spring Boot application for your Config Server.

Maven Dependencies (pom.xml)

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>

Application Main Class

Enable config server functionality with @EnableConfigServer:

package com.tracker.configserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

Server Configuration (application.yml)

server:
  port: 8888

spring:
  application:
    name: config-server
  profiles:
    active: vault
  cloud:
    vault:
      host: localhost
      port: 8200
      scheme: http
      authentication: TOKEN
      token: s.myProductionVaultTokenSecret

๐Ÿ“ก Step 2: Binding Microservice Clients to Config Server

Connect your microservice (payment-service) to pull properties dynamically at startup.

Client Configuration (application.yml)

spring:
  application:
    name: payment-service
  config:
    import: "configserver:http://localhost:8888"
  profiles:
    active: prod

โšก Step 3: Dynamic Refresh without Restart (@RefreshScope)

Annotate beans that consume dynamic properties with @RefreshScope:

package com.tracker.payment.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

@Component
@RefreshScope
public class PaymentGatewayConfig {

    @Value("${payment.stripe.secret-key}")
    private String stripeSecretKey;

    public String getStripeSecretKey() {
        return stripeSecretKey;
    }
}

When you update a property in Vault, trigger a POST request to http://localhost:8082/actuator/refresh to reload the bean instantly without restarting the container!


๐Ÿš€ Production Best Practices

๐Ÿ’ก Production Tip: Centralized config servers can be hosted on minimal 250MB heap RAM instances (costing under โ‚น100/month) while securing sensitive production microservices.

  1. Vault Lease Renewal: Set TTLs on Vault database credentials so DB passwords auto-rotate every 24 hours.

  2. Fail-Fast Configuration: Set spring.cloud.config.fail-fast: true so a microservice immediately fails startup if it cannot connect to the Config Server rather than running with missing properties.


๐ŸŽฏ Summary

Spring Cloud Config and Vault provide production-grade secret management and zero-downtime property updates across distributed microservices.

Series

Production-Grade Microservices Architecture with Java & Spring Boot

Part 2 of 3

PrevNext

Discussion (0)

Login to post a comment.

Shubham Bhati
Shubham Bhati

Java Backend Engineer | Microservices

Backend Engineer with 3+ years of experience building resilient microservices, event-driven pipelines and high-concurrency systems using Java, Spring Boot, Kafka, Redis and PostgreSQL. Engineered fintech transaction routing at MobilePe, B2B logistics pipelines at AlignBits and architected an e-commerce backend hosted under โ‚น100/month in infra costs that generated โ‚น1L+ revenue in 2 months. I write hands-on guides on Spring Cloud, service discovery, database indexing and low-cost architecture patterns.

Subscribe to Shubham Bhati's Newsletter

Direct email dispatches when new stories are published. Zero algorithms.

More from Shubham Bhati

View profile

Event-Driven Microservices with Apache Kafka, Redis Caching and Transactional Outbox Pattern

Master high-throughput event-driven microservices architecture using Java 21, Spring Boot 3.4+, Apache Kafka, Redis distributed locking and the Transactional Outbox Pattern to guarantee zero data loss and sub-10ms P99 latency under traffic spikes.

3 minAug 16

Service Discovery with Eureka and Spring Cloud: A Production Hands-On Guide

Learn how to build production-grade service discovery with Eureka and Spring Cloud LoadBalancer. Includes real-world heartbeat tuning and memory optimization tips.

3 minJul 31