Creating Profiles in Spring Cloud Config Server
Last Updated :
23 Jul, 2025
Spring Cloud Config provides both server-side and client-side support for external systems in a distributed system. Using the Config Server, we can manage the configuration for multiple applications from the central place. Profiles in the Spring Cloud Config can allow you to provide different configurations for the various environments such as development, testing, and production of applications.
Spring Cloud Config
Spring Cloud Config provides both server-side and client-side support for external systems in a distributed system. With the Spring Cloud Config, we can manage the configurations for multiple applications from the central place. It ensures consistency and easier management across different development, testing, and production environments.
Profiles in Spring Cloud Config
Profiles in the Spring Cloud Config allows us to define different sets of configuration properties for different environments. For example, We can might have different database settings, API endpoints or feature toggles for the development, testing and production environments.
Working of Spring Cloud Config
- Config Server: The Spring Boot application that runs the Spring Cloud Config server. It can fetches the configuration properties from the repository and the serves them to the client applications.
- Config Repository: The Git repository where the configurations files are stored then the repository contains the properties files for the different profiles like application-dev.yml, application-test.yml and application-prod.yml.
- Client Applications: Spring Boot applications that can request the configuration properties from the config server. These applications can specify their active profiles and receive the appropriate configuration properties.
Implementation to Create Profiles in Spring Cloud Config Server
We will develop the simple spring boot application that can demonstrates the creating the profiles in spring cloud config server of the project.
Step 1:
Create a new Spring Boot project using Spring Initializr and add the required dependencies,
- Spring Web
- Spring Cloud Config Server
- Lombok
- Spring DevTools
After the creation of the project is done, the folder structure will be like below.

Step 2: Setting up the Configuration Repository
Create the Git repository and add the configuration files for the different profiles of the spring application.
1. application-dev.yml
spring:
config:
activate:
on-profile: prod
cloud:
config:
server:
git:
uri: https://github.com/your-repo/config-repo
search-paths: dev
default-label: dev
message: "This is the development profile"
2. application-prod.yml
spring:
config:
activate:
on-profile: prod
cloud:
config:
server:
git:
uri: https://github.com/your-repo/config-repo
search-paths: prod
default-label: prod
message: "This is the production profile"
3. application-test.yml
spring:
config:
activate:
on-profile: test
cloud:
config:
server:
git:
uri: https://github.com/your-repo/config-repo
search-paths: test
default-label: test
message: "This is the test profile"
Step 3: Setup the Client application
Open the application.properties rename to application.yml and configure the config server uri of the project.
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/iammahesh123/config-repo
message: "This is the default profile"
Step 4: Main Class
Open the main class and add the @EnableConfigServer annotation to activate the config server functionalities of the spring application.
Java
package org.example.springconfigprofiles;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class SpringConfigProfilesApplication {
public static void main(String[] args) {
SpringApplication.run(SpringConfigProfilesApplication.class, args);
}
}
pom.xml:
Java
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.example</groupId>
<artifactId>spring-config-profiles</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-config-profiles</name>
<description>spring-config-profiles</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2023.0.1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Step 5: Run the Application
Now, we will run the application and it will start at port 8888.

Step 6: Verify the Profiles
Default Profile
GET http://localhost:8888/application/default
Output:
Below is the Postman output of default api.

Development Profile
GET http://localhost:8888/application/dev
Output:
Below is the Postman output of dev api.

Production Profile
GET http://localhost:8888/application/prod
Output:
Below is the Postman output of prod api.

Testing Profile
GET http://localhost:8888/application/test
Output:
Below is the Postman output of test api.

This example project demonstrates how to use the Spring Cloud Config Server to the serve different configurations based on the active profile of the client application. We can extend this setup to the include the other properties and configurations as needed.
Similar Reads
Using Native Configuration in Spring Cloud Config Server Spring Cloud Config provides both server-side and client-side support for externalized configuration in distributed systems. The Config Server centralizes management of configuration properties for applications across various environments. By default, Spring Cloud Config uses Git for storage, but it
5 min read
Spring Boot - Cloud Configuration Server In microservices, we have several different services responsible for different functionalities. These services act like smaller application modules, which together form the application. Each of these modules has its own responsibility, based on the business logic of the application being built. Thes
10 min read
Monitoring and Logging in Spring Cloud Config Server In Microservices, Spring Cloud Server can play a crucial role in Spring microservices by providing centralized configuration management. It helps externalize configuration properties across all environments for applications, making them easier to manage and update without redeploying or restarting t
9 min read
Customizing the Configuration Location in Spring Cloud Config Server Spring Cloud Config provides both server and client-side support for externalized configuration in distributed systems. The Config Server manages configuration properties for applications across various environments, allowing them to retrieve their configuration from a central location. By default,
5 min read
Managing Configuration for Microservices with Spring Cloud Config Spring Cloud Config provides the centralized external configuration management system and it is designed to work well with modern microservices architectures. It is the part of larger Spring Config suite of the tools that aim to help the developers built the cloud-native applications. Spring Cloud C
4 min read
Encrypting Sensitive Configuration Data in Spring Cloud Config Encrypting sensitive configuration data in Spring Cloud Config is essential for securing information like passwords, API keys, and other credentials. This extra layer of protection is crucial because it helps prevent unauthorized access and ensures that sensitive data remains safe, even if the confi
4 min read