Categories: Uncategorised

Spring Cloud Config Client

The Spring Cloud Config Client is a component of the Spring Cloud framework that enables applications to access configuration properties stored in a centralized configuration server. It allows for the externalization of configurations from the application code, promoting a more maintainable and flexible architecture.

Spring Cloud Config Server is where the configurations for multiple applications are stored.

During startup, the Config Client contacts the Config Server to obtain the application-specific configuration properties. The client application uses the application name, profile and label information to fetch the relevant configuration.

To set up a Spring Cloud Config Client:

i) Add below dependency

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

ii) Configure the client: In application.properties or application.yml, specify the Config Server’s location, application name, profile and label.

spring.cloud.config.profile=jdbc
spring.cloud.config.label=master
spring.cloud.config.name=spring-config-server-demo
spring.config.import=optional:configserver:http://localhost:8080

iii) Access the configured properties in app as usual

package com.example.springconfigclientdemo.controller;

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

@RestController
public class SpringConfigClientController {
 
 @Value("${greeting}")
 String greeting;

 @GetMapping("/greet")
 public String greet() {
  
  return greeting;
 }
}

For complete source code: https://github.com/MMahendravarman/Springboot_Examples

mahendravarman.m@gmail.com

Recent Posts

Spring Webflux Functional Endpoint – File Upload

In this blog using the Spring WebFlux module, we are going to leverage the functional…

12 months ago

Serverless Functions with Spring Cloud Function, AWS Lambda

Spring Cloud Function is a project within the Spring ecosystem that allows developers to build…

12 months ago

Spring Boot + RabbitMQ – Decoupling Microservices Communication

RabbitMQ is an open-source message broker software that implements the Advanced Message Queuing Protocol (AMQP).…

1 year ago

Spring Integration – Sending files over SFTP

Spring Integration is a powerful extension of the Spring Framework designed to support the implementation…

1 year ago

Handling CSV in Python

In Python, handling CSV (Comma Separated Values) files is easy using the built-in csv module.…

1 year ago

Spring Cloud Config Server – JDBC Backend

Spring Cloud Config Server provides a centralized location for managing and serving configuration information to…

1 year ago