Spring Cloud Config Server
Spring Cloud Config Server offers the following benefits:
HTTP resource-based API for external configuration (name-value pairs or equivalent YAML content)
Encrypt and decrypt property values (symmetric or asymmetric)
Embeddable easily in a Spring Boot application using
Spring Cloud Config Client
Specifically for Spring applications, Spring Cloud Config Client lets you:
Bind to the Config Server and initialize Spring
Environmentwith remote property sources.
Encrypt and decrypt property values (symmetric or asymmetric).
@Beansthat want to be re-initialized when configuration changes.
Use management endpoints:
@ConfigurationPropertiesand log levels.
/refreshfor refreshing the
/restartfor restarting the Spring context (disabled by default).
/resumefor calling the
Bootstrap application context: a parent context for the main application that can be trained to do anything (by default, it binds to the Config Server and decrypts property values).
You can find a sample application here.
It is a Spring Boot application, so you can run it by using the usual mechanisms (for instance,
When it runs, it looks for the config server on
http://localhost:8888 (a configurable default), so you can run the server as well to see it all working together.
The sample has a test case where the config server is also started in the same JVM (with a different port), and the test asserts that an
environment property from the git configuration repo is present.
To change the location of the config server, you can set
bootstrap.yml (or in system properties and other places).
The test case has a
main() method that runs the server in the same way (watch the logs for its port), so you can run the whole system in one process and play with it (for example, you can run the
main() method in your IDE).
main() method uses
target/config for the working directory of the git repository, so you can make local changes there and see them reflected in the running app. The following example shows a session of tinkering with the test case:
$ curl localhost:8080/env/sample mytest $ vi target/config/mytest.properties .. change value of "sample", optionally commit $ curl localhost:8080/refresh ["sample"] $ curl localhost:8080/env/sample sampleValue
The refresh endpoint reports that the "sample" property changed.
If you get an exception due to "Illegal key size" and you are using Sun’s JDK, you need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files. See the following links for more information:
Extract the JCE files into the
JDK/jre/lib/security folder for whichever version of JRE/JDK x64/x86 you use.