@SpringBootApplication
+@EnableConfigServer
+public class ConfigServer {
+ public static void main(String[] args) {
+ SpringApplication.run(ConfigServer.class, args);
+ }
+}
+From ca95da7e772de22d48499eeb03b3ea60b0b8b8cd Mon Sep 17 00:00:00 2001
From: Dave Syer Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring The Server provides an HTTP, resource-based API for external
configuration (name-value pairs, or equivalent YAML content). The
server is easily embeddable in a Spring Boot application using the
- Like all Spring Boot apps it runs on port 8080 by default, but you
+can switch it to the conventional port 8888 in various ways. The
+easiest, which also sets a default configuration repository,
+is by launching it with where Here’s a recipe for creating the git repository in the example
+above: Spring Cloud Config Server supports a single or multiple git
-repositories: In the above example, if {application} does not match to any of the
-patterns, it will use the default uri defined under
-"spring.cloud.config.server.git.uri". For the "simple" repository, the
-pattern is "simple" (i.e. it only matches one application). The
-pattern format is a comma-separated list of application names with
-wildcards. If The Every repository can also optionally store config files in
@@ -1004,6 +1138,16 @@ instance: Encrypted values in a .properties file must not be wrapped in quotes, otherwise the value will not be decrypted: You can safely push this plain text to a shared git repository and the
secret password is protected.
Environment and PropertySource abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.@EnableConfigServer annotation.@EnableConfigServer annotation. So this app is a config server:
+
+@SpringBootApplication
+@EnableConfigServer
+public class ConfigServer {
+ public static void main(String[] args) {
+ SpringApplication.run(ConfigServer.class, args);
+ }
+}spring.config.name=configserver (there
+is a configserver.yml in the Config Server jar). Another is
+to use your own application.properties, e.g.
+server.port: 8888
+spring.cloud.config.server.git.uri: file://${HOME}/config-repo${HOME}/config-repo is a git repository containing
+YAML and properties files.
+
+
+
+
+
+
+
+$ 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"
+
+
+
+
+
+
+using the local filesystem for your git repository is
+intended for testing only. Use a server to host your
+configuration repositories in production.
+
+Environment Repository
@@ -757,7 +827,10 @@ them from the shell with quotes '').
{application}/{profile} names with wildcards (where a pattern
+beginning with a wildcard may need to be quoted). Example:
{application}/{profile} does not match any of the patterns, it
+will use the default uri defined under
+"spring.cloud.config.server.git.uri". In the above example, for the
+"simple" repository, the pattern is simple/* (i.e. it only matches
+one application named "simple" in all profiles). The "local"
+repository matches all application names beginning with "local" in all
+profiles (the /* suffix is added automatically to any pattern that
+doesn’t have a profile matcher).
+
+
+
+
+
+
+the "one-liner" short cut used in the "simple" example above can
+only be used if the only property to be set is the URI. If you need to
+set anything else (credentials, pattern, etc.) you need to use the full
+form.
+
+pattern property in the repo is actually an array, so you can
+use a YAML array (or [0], [1], etc. suffixes in properties files)
+to bind to multiple patterns. You may need to do this if you are going
+to run apps with multiple profiles. Example:spring:
+ cloud:
+ config:
+ server:
+ git:
+ uri: https://github.com/spring-cloud-samples/config-repo
+ repos:
+ development:
+ pattern:
+ - */development
+ - */staging
+ uri: https://github.com/development/config-repo
+ staging:
+ pattern:
+ - */qa
+ - */production
+ uri: https://github.com/staging/config-repo
+
+
+
+
+
+
+Spring Cloud will guess that a pattern containing a profile that
+doesn’t end in
+* implies that you actually want to match a list of
+profiles starting with this pattern (so */staging is a shortcut for
+["*/staging", "*/staging,*"]). This is common where you need to run
+apps in the "development" profile locally but also the "cloud" profile
+remotely, for instance.
+spring.datasource.username: dbuser
+spring.datasource.password: {cipher}FKSAJDFGYOS8F7GLHAKERGFHLSAJ
+
|
+ Tip
+ |
+
+If you are testing like this with curl, then use
+--data-urlencode (instead of -d) or set an explicit Content-Type:
+text/plain to make sure curl encodes the data correctly when there
+are special characters ('+' is particularly tricky).
+ |
+
Take the encypted value and add the {cipher} prefix before you put
+
Take the encrypted value and add the {cipher} prefix before you put
it in the YAML or properties file, and before you commit and push it
-to a remote, potentially insecure store. The /encypt and /decrypt
+to a remote, potentially insecure store. The /encrypt and /decrypt
endpoints also both accept paths of the form /*/{name}/{profiles}
which can be used to control cryptography per application (name)
and profile when clients call into the main Environment resource.
To use a key in a file (e.g. an RSA public key for encyption) prepend +
To use a key in a file (e.g. an RSA public key for encryption) prepend the key value with "@" and provide the file path, e.g.
Instead of using the Environment abstraction (or one of the
+alternative representations of it in YAML or properties format) your
+applications might need generic plain text configuration files,
+tailored to their environment. The Config Server provides these
+through an additional endpoint at /{name}/{profile}/{label}/{path}
+where "name", "profile" and "label" have the same meaning as the
+regular environment endpoint, but "path" is a file name
+(e.g. log.xml). The source files for this endpoint are located in
+the same way as for the environment endpoints: the same search path is
+used as for properties or YAML files, but instead of aggregating all
+matching resources, only the first one to match is returned.
After a resource is located, placeholders in the normal format
+(${…}) are resolved using the effective Environment for the
+application name, profile and label supplied. In this way the resource
+endpoint is tightly integrated with the environment
+endpoints. Example, if you have this layout for a GIT (or SVN)
+repository:
application.yml +nginx.conf+
where nginx.conf looks like this:
server {
+ listen 80;
+ server_name ${nginx.server.name};
+}
+and application.yml like this:
nginx:
+ server:
+ name: example.com
+---
+spring:
+ profiles: development
+nginx:
+ server:
+ name: develop.com
+then the /foo/default/master/nginx.conf resource looks like this:
server {
+ listen 80;
+ server_name example.com;
+}
+and /foo/development/master/nginx.conf like this:
server {
+ listen 80;
+ server_name develop.com;
+}
+|
+ Note
+ |
+
+just like the source files for environment configuration, the
+"profile" is used to resolve the file name, so if you want a
+profile-specific file then /*/development/*/logback.xml will be
+resolved by a file called logback-development.xml (in preference
+to logback.xml).
+ |
+
The Config Server runs best as a standalone application, but if you need to you can embed it in another application. Just use the @@ -1220,6 +1479,70 @@ initialize the same way as any other application.
Many source code repository providers (like Github, Gitlab or Bitbucket
+for instance) will notify you of changes in a repository through a
+webhook. You can configure the webhook via the provider’s user
+interface as a URL and a set of events in which you are
+interested. For instance
+Github
+will POST to the webhook with a JSON body containing a list of
+commits, and a header "X-Github-Event" equal to "push". If you add a
+dependency on the spring-cloud-config-monitor library and activate
+the Spring Cloud Bus in your Config Server, then a "/monitor" endpoint
+is enabled.
When the webhook is activated the Config Server will send a
+RefreshRemoteApplicationEvent targeted at the applications it thinks
+might have changed. The change detection can be strategized, but by
+default it just looks for changes in files that match the application
+name (e.g. "foo.properties" is targeted at the "foo" application, and
+"application.properties" is targeted at all applications). The strategy
+if you want to override the behaviour is PropertyPathNotificationExtractor
+which accepts the request headers and body as parameters and returns a list
+of file paths that changed.
The default configuration works out of the box with Github, Gitlab or
+Bitbucket. In addition to the JSON notifications from Github, Gitlab
+or Bitbucket you can trigger a change notification by POSTing to
+"/monitor" with a form-encoded body parameters path={name}. This will
+broadcast to applications matching the "{name}" pattern (can contain
+wildcards).
|
+ Note
+ |
+
+the RefreshRemoteApplicationEvent will only be transmitted if
+the spring-cloud-bus is activated in the Config Server and in the
+client application.
+ |
+
|
+ Note
+ |
++the default configuration also detects filesystem changes in +local git repositories (the webhook is not used in that case but as +soon as you edit a config file a refresh will be broadcast). + | +