ZyVOP Logo
Content That Connects
SeriesAI NewsCategoriesWrite for Us
ZyVOP Logo
Content That Connects

Empowering developers and creators with cutting-edge insights, comprehensive tutorials, and innovative solutions for the digital future.

Content

  • Tags
  • Badges
  • Write Article
  • Newsletter

Company

  • About Us
  • Write for Us
  • Contact

Connect

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

© 2026 ZyVOP. Crafted with care for the developer community.

Made with ❤️ by the ZyVOP team
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 BhatiJava Backend Engineer | Microservices
August 1, 2026
2 min read
2 views
Series

Production-Grade Microservices Architecture with Java & Spring Boot

Part 2 of 2

Prev
Next
Centralized Secret Management with Spring Cloud Config & Vault: A Production Guide
#springboot#java#Microservices#springcloud#backend#security
👍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.

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.

Series

Production-Grade Microservices Architecture with Java & Spring Boot

Part 2 of 2

Prev
Next

Discussion (0)

Login to post a comment.

Related Posts

The Alpine Mirage: How Upgrading Python Broke My Build and Led to a Truer Security Posture

A deep dive into how upgrading a Python Docker image to Alpine 3.15 caused cascading build failures across C/Rust dependencies—and why switching to Debian-slim with non-root privileges resulted in a faster, truly secure container architecture.

Read article

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.

Read article

Authentication in React: Buy It, and Where the Line Really Is

Authentication always starts as a login form. Two fields and a button. You could build that in an afternoon, and that afternoon is exactly the trap. Because the...

Read article

The Backend a React Developer Actually Needs to Understand

"That's a backend concern" is one of the most expensive sentences a frontend developer can say. I understand the instinct. There's a clean line in most people's...

Read article

Payments in React: The Client Never Decides You Got Paid

On the surface, taking a payment looks like the most ordinary thing in the world: a form with some fields, a submit button, a success message. You've built a hu...

Read article