- Spring Boot - Google OAuth2 Sign-In
- Spring Boot - Google Cloud Platform
- Spring Boot - OAuth2 with JWT
- Securing Web Applications
- Spring Boot - Database Handling
- Rest Controller Unit Test
- Spring Boot - Unit Test Cases
- Spring Boot - Twilio
- Spring Boot - Apache Kafka
- Spring Boot - Batch Service
- Spring Boot - Web Socket
- Spring Boot - Hystrix
- Spring Boot - Sending Email
- Spring Boot - Flyway Database
- Tracing Micro Service Logs
- Spring Boot - Creating Docker Image
- Spring Boot - Enabling Swagger2
- Spring Boot - Admin Client
- Spring Boot - Admin Server
- Spring Boot - Actuator
- Spring Cloud Configuration Client
- Spring Cloud Configuration Server
- Zuul Proxy Server and Routing
- Service Registration with Eureka
- Spring Boot - Eureka Server
- Spring Boot - Enabling HTTPS
- Spring Boot - Scheduling
- Spring Boot - Internationalization
- Spring Boot - CORS Support
- Consuming RESTful Web Services
- Spring Boot - Thymeleaf
- Spring Boot - Service Components
- Spring Boot - File Handling
- Spring Boot - Rest Template
- Spring Boot - Tomcat Port Number
- Spring Boot - Servlet Filter
- Spring Boot - Interceptor
- Spring Boot - Exception Handling
- Building RESTful Web Services
- Spring Boot - Logging
- Spring Boot - Application Properties
- Spring Boot - Runners
- Spring Beans & Dependency Injection
- Spring Boot - Code Structure
- Spring Boot - Build Systems
- Spring Boot - Tomcat Deployment
- Spring Boot - Bootstrapping
- Spring Boot - Quick Start
- Spring Boot - Introduction
- Spring Boot - Home
Spring Boot Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Spring Boot - Cloud Configuration Cpent
Some apppcations may need configuration properties that may need a change and developers may need to take them down or restart the apppcation to perform this. However, this might be lead to downtime in production and the need of restarting the apppcation. Spring Cloud Configuration Server lets developers to load the new configuration properties without restarting the apppcation and without any downtime.
Working with Spring Cloud Configuration Server
First, download the Spring Boot project from
and choose the Spring Cloud Config Cpent dependency. Now, add the Spring Cloud Starter Config dependency in your build configuration file.Maven users can add the following dependency into the pom.xml file.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
Gradle users can add the following dependency into the build.gradle file.
compile( org.springframework.cloud:spring-cloud-starter-config )
Now, you need to add the @RefreshScope annotation to your main Spring Boot apppcation. The @RefreshScope annotation is used to load the configuration properties value from the Config server.
package com.example.configcpent; import org.springframework.boot.SpringApppcation; import org.springframework.boot.autoconfigure.SpringBootApppcation; import org.springframework.cloud.context.config.annotation.RefreshScope; @SpringBootApppcation @RefreshScope pubpc class ConfigcpentApppcation { pubpc static void main(String[] args) { SpringApppcation.run(ConfigcpentApppcation.class, args); } }
Now, add the config server URL in your apppcation.properties file and provide your apppcation name.
Note − http://localhost:8888 config server should be run before starting the config cpent apppcation.
spring.apppcation.name = config-cpent spring.cloud.config.uri = http://localhost:8888
The code for writing a simple REST Endpoint to read the welcome message from the configuration server is given below −
package com.example.configcpent; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApppcation; import org.springframework.boot.autoconfigure.SpringBootApppcation; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApppcation @RefreshScope @RestController pubpc class ConfigcpentApppcation { @Value("${welcome.message}") String welcomeText; pubpc static void main(String[] args) { SpringApppcation.run(ConfigcpentApppcation.class, args); } @RequestMapping(value = "/") pubpc String welcomeText() { return welcomeText; } }
You can create an executable JAR file, and run the Spring Boot apppcation by using the following Maven or Gradle commands −
For Maven, you can use the command shown below −
mvn clean install
After “BUILD SUCCESS”, you can find the JAR file under the target directory.
For Gradle, you can use the command shown below −
gradle clean build
After “BUILD SUCCESSFUL”, you can find the JAR file under the build/pbs directory.
Now, run the JAR file by using the command shown here:
java –jar <JARFILE>
Now, the apppcation has started on the Tomcat port 8080 as shown here −
You can see the log in console window; config-cpent apppcation is fetching the configuration from the https://localhost:8888
2017-12-08 12:41:57.682 INFO 1104 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
Now hit the URL, http://localhost:8080/ welcome message is loaded from the Configuration server.
Now, go and change the property value on the Configuration server and hit the actuator Endpoint POST URL http://localhost:8080/refresh and see the new configuration property value in the URL http://localhost:8080/
Advertisements