The Spring Cloud Services Config Server can serve configuration properties from either Git or HashiCorp Vault configuration sources. Configuration properties can be applicable to all apps that use the Config Server, specific to an app, or specific to a Spring application profile.
Git
If you are using a Git configuration source, you must store properties in YAML or Java .properties files.
Global configuration
You can store configuration properties so that they are served to all apps that use the Config Server. In the configuration repository, a file named application.yml
or application.properties
contains configuration that will be served to all apps that access the Config Server.
Example | |
---|---|
Using YAML | Global application.yml file
|
Using a properties file | Global application.properties file
|
Application-specific configuration
You can store configuration properties so that they are served only to a specific app. In the configuration repository, a file named [APP-NAME].yml
or [APP-NAME].properties
, where [APP-NAME]
is the name of an app, contains configuration that will be served only to the APP-NAME
app.
Example | |
---|---|
Using YAML | App-specific cook.yml file:
|
Using a properties file | App-specific cook.properties file:
|
Profile-specific configuration
You can store configuration properties so that they are served only to apps that have activated a specific Spring application profile. In the configuration repository, a file named [APP-NAME]-[PROFILE-NAME].yml
or [APP-NAME]-[PROFILE-NAME].properties
, where [APP-NAME]
is the name of an app and [PROFILE-NAME]
is the name of an application profile, contains configuration that will be served only to the APP-NAME
app running with the [PROFILE-NAME]
profile activated.
Within a YAML file named [APP-NAME].yml
, a document that begins by setting the spring.profiles
property contains configuration that will be served only to the APP-NAME
app running with the profile specified by the spring.profiles
property.
Example | |
---|---|
Using YAML | Profile-specific cook-dev.yml file:
|
Using YAML | Profile-specific YAML document within cook.yml file:
|
Using a properties file | profile-specific cook-dev.properties file:
|
Encrypted configuration
Support for decrypting encrypted configuration was added in Spring Cloud Services for Cloud Foundry v3.1.6.
You can store configuration properties in encrypted form and have these properties decrypted by the Config Server before they are served to apps. In a file within the configuration repository, properties whose values are prefixed with {cipher}
will be decrypted before they are served to client apps. To use this feature, you must configure the Config Server with an encryption key as described in Encryption and Encrypted Values.
Example | |
---|---|
Using YAML | The encrypted property value must be surrounded by single quotes. Encrypted property value in an application.yml file:
|
Using a properties file | Encrypted property value in an application.properties file:
|
Plain text configuration
You can store configuration in files of other file types. The Spring Cloud Services Config Client library includes a PlainTextConfigClient
that can be used to retrieve the contents of a plain text file as a Spring Resource
.
For more information about using the Config Server to serve plain text files to a client app, see the Use Plain Text Configuration Files section of Writing Client Applications.
HashiCorp Vault
If you are using a HashiCorp Vault configuration source, you must write secrets to the Vault server using the vault
CLI tool. For more information about the Vault CLI tool, see the HashiCorp Vault documentation.
Global configuration
You can store configuration properties so that they are served to all apps that use the Config Server. A secret written to the secret/application
path will be served to all apps that access the Config Server.
An example of setting a global configuration property:
$ vault write secret/application message=Greetings
Application-specific configuration
You can store configuration properties so that they are served only to a specific app. A secret written to the secret/[APP-NAME]
path contains configuration that will be served only to the APP-NAME
app.
An example of setting an app-specific configuration property:
$ vault write secret/cook message=Hi
Profile-specific configuration
You can store configuration properties so that they are served only to apps that have activated a specific Spring application profile. A secret written to the secret/[APP-NAME],[PROFILE-NAME]
path, where [APP-NAME]
is the name of an app and [PROFILE-NAME]
is the name of an application profile, contains configuration that will be served only to the APP-NAME
app running with the [PROFILE-NAME]
profile activated.
An example of setting a profile-specific configuration property:
$ vault write secret/cook,dev message=Ho
Content feedback and comments