How to start with Spring Cloud Centralized Configuration

Spring Cloud provides an excellent mechanics to refresh all configured properties of a Spring Bean by @RefreshScope. So in the tutorial, JavaSampleApproach will introduce way to config Spring Cloud Centralized Configuration and the benifits of @RefreshScope.

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.3.RELEASE

II. Overview
1. Project Structure

spring cloud - project structure

2. Step to do

– Create SpringBoot projects
– Configure for Spring Cloud Server
– Configure for Spring Cloud Client
– Create a RestController with RefreshScope
– Run & Enjoys Result

III. Practices
1. Create SpringBoot projects

Create 2 Spring Boot projects for Spring Cloud Server & Spring Cloud Client

Open Spring Tool Suite, on main menu, choose New->File->Spring Starter Project, input project info. Press Next, then Finish. Spring Boot project will be created.

For Spring Cloud Server, add Cloud Config Server dependency:


For Spring Cloud Client, add dependencies: cloud-starter-config, spring-boot-starter-actuator & spring-boot-starter-web:


2. Configure Spring Cloud Server

– Create a file in: src/main/resources, with simple content:
message = Hello world!.
– In, add config:

We have many choices to define a repository for Cloud Server: Git, Svn, Filesystem. For simple approach, in the tutorial, Repository is a FileSystem by configs:

3. Configure Spring Cloud Client

Client need pointers to the Cloud Server:

4. Create RestController with RefreshScope

Create a simple RestController for loading the config properties:

package com.javasampleapproach.cloudconfigclient.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

class WebController {

    @Value("${message:Hello default}")
    private String message;

    String getMessage() {
        return this.message;

@RefreshScope is used to force a bean to refresh its configuration – to pull updated values from the Config Server.

5. Run & Enjoys Result

Run with Spring Boot App mode by order:
1. Run Cloud Server
2. Run Cloud Client


– Request 1
Get all configs on Server side
Spring Cloud Centralized Configuration - server default request

– Request 2
Spring Cloud Centralized Configuration - client get msg request

Modified message in file: message = Modified Message!

– Request 3
Spring Cloud Centralized Configuration - server see modified request

– Request 4
Spring Cloud Centralized Configuration - client post refresh request

– Request 5
Spring Cloud Centralized Configuration - client get modified msg request

IV. Source Code


By grokonez | January 24, 2017.

Last updated on June 20, 2017.

Related Posts

2 thoughts on “How to start with Spring Cloud Centralized Configuration”

  1. If the application is not hosted in cloud, then can we make use of spring config server to have externalized configuration. We are having spring batch jobs. Is this approach recommended for batch jobs.?

    1. Hello Pooja,

      Remmeber that SpringCloud does NOT mean ‘hosted services on Cloud’. SpringCloud helps us to build the common patterns in distributed systems.

      For your system, you can use Spring Cloud Centralized Configuration to central all your system config for batch job.

      Or it may be useful for your system if designed with Client Load Balancing, refer more at Spring Cloud Ribbon.

      When you want control Routing and Filtering with RestAPI requests in your system, you can use SpringCloud Zuul.


Got Something To Say:

Your email address will not be published. Required fields are marked *