Resources:
Https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.0.RELEASE/single/spring-cloud-config.html
http://cloud.spring.io/spring-cloud-static/Camden.SR7/#_spring_cloud_config_server
The server provides an HTTP, resource-based API for external configuration (Name-value pairs or equivalent yaml content). The server @EnableConfigServer
is easily embedded in the spring boot application using annotations. So this program is a configuration server:
ConfigServer.java
@SpringBootApplication @enableconfigserverpublic class configserver {public static void main (string[] args) { springapplication.run (Configserver.class, args);} }
Like all spring boot applications, it will run on port 8080 by default, but you can switch it to regular port 8888 in a variety of ways. The simplest is also to set a default configuration library by spring.config.name=configserver
(in the config Server jar there is a configserver.yml
) to start it. The other is to use your own application.properties, for example:
Application.properties
Server.port:8888spring.cloud.config.server.git.uri:file://${user.home}/config-repo
Which ${user.home}/config-repo
is a git repository containing Yaml and properties files.
Note: In Windows, if the URL is an absolute path with a driver prefix, you need to add an extra "/" to the URL, for example:file:///${user.home}/config-repo
TIP: Here's how to create a git repository in the example above:
$ cd $HOME $ mkdir config-repo$ cd config-repo$ git init. $ echo info.foo:bar > application.properties$ git Add-A. $ git commit-m "add application.properties"
WARNING: Use the local file system for git repositories for testing only. Use the server to host the configuration library in a production environment.
WARNING: If you keep only text files, the initial cloning of the configuration library will be quick and efficient. If you start to store binaries, especially large files, you may experience a delay in the first configuration request and/or out-of-memory error in the server.
Spring-cloud-config-server