There are various tools and dependencies which are available
in Spring Starter project which are very useful in creating better spring based
microservice architectures for developing mobile or web applications. Here is
one such commonly used tools if you are using the springboot microservice architecture in designing your applications.
Spring Cloud Config
Server : This dependency is used for externalizing the configuration
properties in various microservices present in your organization. The main
advantage of using Spring Cloud Config Server is that you can get away from
deploying or restarting your services if there is only configuration change
made in your microservice. Generally, if you change any property in your
microservice, you will have to restart the microservice to see that change. But
if you configure your properties in the Spring Cloud Config Server, the changes
will be affected automatically in the applications.
Steps to activate this dependency:
·
Create a github repo and place the property
files from your microservices in git hub repository.
·
If there are common properties across microservices,
then create a file called application.properties.
·
Application specific properties can be placed in
files called
“ApplicationName.properties” . For example, if you have defined an
application as “Customer”, then Customer application specific poperties will be
defined in “Customer.properties”.
- Create a new project called “Config-Server” for Config Server. In this springboot starter project just select “Config Server” as dependency
- Open application.properties file in “Config-Server” project. Add following properties:
- Spring.application.name
- Server.port
- Spring.cloud.config.server.git.uri=https://github.com/ravivv247/spring-cloud-config
- Add class level annotation @EnableConfigServer for the springboot main class file created in “Config-Server” project.
- Start the “Config-Server” project. Check the below URL to see if the “Config-Server” is running properly.
Configuring Config Cloud Server in the microservices:
- Add “spring-cloud-starter-config” dependency in the the microservice.
- Add bootstrap.properties files under resources folder. Bootstrap context runs even before the application context runs.
- Add following property in the bootstrap.properties file.
- Spring.cloud.config.uri = http://localhost:PortOfConfigServer
Comments
Post a Comment