This project is an attempt to demonstrate the usage of spring cloud config for centralizing external configurations.
This project contains 3 sub projects:
- serviceregistry - plays as the eureka server
- config-server - serves the configurations
- config-client - fetches configurations from the config-server internally
- config-client and config-server are integrated with eureka server (no need to set the address of config server manually).
- a relational storage is utilized in config-server (here h2 database is used ).
- configurations are encrypted in a symmetric way.
- api exposed by config-server are secured by basic authentication.
This modules is the eureka server with the minimum configuration. It listens on port 8761 and its address is hardcoded in config-server and config-client
config-server uses spring-cloud-config for centralizing configuration. It uses H2 database for storing configuration. Also apis exposed by this module, which are used by config-client for fetching configurations, are secured using basic authentication.
There are 2 built-in apis which worth elaborating:
- /encrypt : this api is used for encrypting data using the provided key for the config-server.
- /decrypt : as the name suggests encrypted values can get decrypted using this api.
This is a typical spring boot project which fetches its configurations from the config-server. This module contains a custom api which returns the value of a configuration which is expected to be fetched during startup. By sending a GET request to /get api the value of the configuration will be returned as response.
- git
- at least oracle jdk8
-
git clone https://github.com/ali4j/cloud-condig-sample.git -
mavenw clean install -DskipTestsafter successful build, first run eureka server
-
cd serviceregistry\target -
java -jar serviceregistry-0.0.1-SNAPSHOT.jarthen start the config-server
-
cd ..\..\SpringBootCloudConfig\target -
java -jar SpringBootCloudConfig-0.0.1-SNAPSHOT.jarfinally start the config-client
-
cd ..\..\springbootcloudconfigclient\target -
java -jar springbootcloudconfigclient-0.0.1-SNAPSHOT.jar
Notes:
**key** is used as the key value for encryption process.
**test** and **test** are used as username and password of basic authentication for config-server exposed apis.
After suuceesfully running config server, it is possible to test the api exposed by it. Based on the provided security config /encrypt and /decrypt apis are available anonymously.
As the image shows the encrypted value of 123456 is 0ee121580e05834c79ab972d9f542c03c8cfb752fbf08d027a4f0d441ab8ce05.
The image below should how to get the stored configurations from config server:
config-client is expected to fetch configurations at startup. By calling /get api from config-client a key-value which is fetch from config-server is injected in to the controller and its value is returned as the response of get request.


