Cloud Config Client AutoConfig
Description
Spring Auto-configuration library for Cloud Config Client.
Cloud Config Client AutoConfig 3.3.x is compatible with
Dependency | Version |
---|---|
Spring Boot | 2.4.x |
Spring Cloud Services | 3.2.x.RELEASE |
Cloud Config Client AutoConfig 3.2.x is compatible with
Dependency | Version |
---|---|
Spring Boot | 2.2.x - 2.3.x |
Spring Cloud Services | 3.1.x.RELEASE |
Cloud Config Client AutoConfig 2.x is compatible with
Dependency | Version |
---|---|
Spring Boot | 2.1.x |
Spring Cloud Services | 2.x.x.RELEASE |
Cloud Config Client AutoConfig 1.x is compatible with
Dependency | Version |
---|---|
Spring Boot | 1.5.x |
Spring Cloud Services | 1.5.x.RELEASE |
Creates Spring Beans for DecryptConfigClient
, EncryptConfigClient
, FileConfigClient
, and PublicKeyClient
. Simply inject the beans where needed.
Usage
To use, add the following as a dependency,
<dependency>
<groupId>io.github.piszmog</groupId>
<artifactId>cloud-config-client-autoconfig</artifactId>
<version>${cloud-config-client-autoconfig.version}</version>
</dependency>
Local Config Server
Local Config Server is considered a locally running application setup as a Config Server. (see Spring Config Server).
Spring Cloud Config Server (PCF)
When deploying applications to PCF, a Config Server service can be created to. Once created, applications deployed to the space can bind to the service.
Disabling Clients
To disable any of the clients, add the following to the application's configuration file.
cloud:
config:
client:
decrypt:
enabled: false
encrypt:
enabled: false
file:
enabled: false
publickey:
enabled: false
Loading Files
FileConfigClient
bean allows for the ability to pull down files either from a specified branch or from the default branch.
If pulling from the default branch, files must be located in a subdirectory.
Adding JSON Files as Property Sources
The Config Server Client will only pull down .properties
and .yml
/.yaml
files for an application's configuration (property sources). As more microservices move to code by configuration, these files can get very large and hard to maintain. Splitting configurations out into JSON files that do not need to follow the Config Server's naming convention can help to better organize an application configuration.
Leveraging the FileConfigClient
bean, JSON files can be loaded as property sources. This allows for ConfigurationProperties
to have JSON values be injected into their fields.
To add a file as a property source, update the application configuration to have the following,
cloud:
config:
client:
file:
resources:
- directory: <sub-directory path>
files:
- <file>
- <file>
...
- directory: <sub-directory path>
files:
- <file>
- <file>
...
...
Where,
<sub-directory path>
is the directory path to the following files -- examplenonprod/example
orconfigs
- Sub-directory must not be
null
or blank.
- Sub-directory must not be
<file>
is the JSON, YAML, or Properties file to load that is located in the specified sub-directory
Specifying Configuration
Adding JSON files to be property sources can either be done in the bootstrap.yml
(embedded with the application), in an embedded application configuration, or in the Config Server.