Updated April 1, 2023
Definition of Spring Cloud Config
Spring cloud config is providing support of externalized configuration for a server-side and client-side system which was distributed. Using this we can manage the external properties of our all applications in a central place. Basically, spring boot config is the concept of client and server which was mapped identically in spring property source and environment. Using this, the environment and property source file are fit into the application very well.
What is spring cloud config?
- At the time of developing our application is going from development to testing environment and then it will be going into the production environment, we can manage configuration in all environment using spring boot config, also it will manage all the thing which was required for the application for transferring it from one environment to another environment.
- By default, It is implemented in git, so it will support the configuration of labeled version environment as well as it will accessible from managing content.
- It is easy to add implementation and plug the same with spring configuration.
- It is nothing but the client and server approach which was used to serve distributed configuration in multiple environments.
- The configuration is stored in a version of git and it can be modified at the runtime of our application.
- It is easy to fit into all spring applications by using all file format which was supported for the application.
Creating spring cloud config
- First, we need to setup config server after creating config server we need to build the client which was used to consume the configuration at the time of server startup.
- To develop an application we need the following software are as follows.
1) JDK 1.8 or later
2) Spring tool suite or Intellij IDEA
3) Maven 3.2+ or gradle 4+
4) IDE
- To start the application we need a git source repository we can download it or we can clone it from git.
- At the time of creating the project template using spring initializer, we need to select config client or config server, spring web, and spring boot actuator dependency. This package is automatically added all dependency packages which was required to develop the application.
- We can develop our regular spring boot application.
Spring cloud config quick start
- To set up the project first step is to create a template by using spring initializer.
- After creating the project template, we need to add spring cloud config dependency in pom.xml file of our application.
- After adding dependency next step is to configure the implementation of server. We have used EnableConfigServer and SpringBootApplication annotation to config the server.
- After implementing config server next step is to add our project in git repository as storage of configuration. In this step, we are initializing git repository by using configured URL.
- After initializing git repository next step is querying our configuration changes by using server path.
- After configuration, we have implemented the client of our application. We can implement client in easy steps.
- After client implementation, we are implementing encryption and decryption in our application.
- We can also provide enhanced security for the application.
Spring cloud config Server
The below example shows server implementation which is as follows.
1) Create a project template for the application –
In the below step, we have provided project group name as com. example, artifact name as springcloudconfig, project name as springcloudconfig, and selected java version as 8.
Group – com.example
Artifact name – springcloudconfig
Name – springcloudconfig
Spring boot – 2.6.0
Project – Maven
Project Description – Project for springcloudconfig
Java – 8
Dependencies – spring web, config server, spring boot actuator
Package name – com.example.springcloudconfig
2) After generating project extract files and open this project by using spring tool suite –
After generating the project by using spring initializer in this step we are extracting the jar file and opening the project by using the spring tool suite.
3) After opening project using spring tool suite check the project and its files –
In this step, we are checking all the project template files. We also need to check maven dependencies and system libraries.
4) Add dependency packages –
In this step, we are adding the required dependency to our project.
Code:
<dependency> -- Start of dependency tag.
<groupId>org.springframework.cloud</groupId> -- Start and end of groupId tag.
<artifactId>spring-cloud-config-server</artifactId> -- Start and end of artifactId tag.
</dependency> -- End of dependency tag.
5) Download and install git –
6) Create new directory using git –
Code:
# mkdir git-springconfig
# cd git-springconfig
7) Initialize git directory –
Code:
# git init
8) Add git folder to project –
9) Edit application. properties file
Code:
limits-service.maximum = 888
limits-service.minimum = 8
10) Add username and email
Code:
# git config --global user.email [email protected]
# git config --global user.name "pqr"
# git add -A
11) Run the application –
Server uses SSH configuration and properties
- We can also use SSH configuration in the spring cloud config project. JGit requires the PEM format RSA keys.
- To use SSH authentication in the remote repository we need to add username and password separately in the properties file.
- It is the centralized application that was used to manage all the configuration related properties.
- To develop an application we need to add spring cloud config server dependency in pom.xml file.
- We can develop our application by using maven or gradle language. For developing applications using spring cloud config first we need cloud service which was act like an intermediate between repository version controlled configuration files and our spring application.
Conclusion
Spring cloud config is nothing but the client and server approach which was used for serving distributed configuration. Using spring cloud config we can manage the external properties of all applications. Spring cloud config is providing support of externalized configuration for server side and client-side system which was distributed.
Recommended Articles
This is a guide to Spring Cloud Config. Here we discuss the definition, What is spring cloud-config, Spring cloud config Server respectively. You may also have a look at the following articles to learn more –