From d370dcddc7ff7760503bcaa6ff68c09f5e3d9659 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Sun, 20 Dec 2020 13:48:19 -0500 Subject: [PATCH] Documents new default way of using spring.config.import Fixes gh-278 --- .../main/asciidoc/spring-cloud-zookeeper.adoc | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/spring-cloud-zookeeper.adoc b/docs/src/main/asciidoc/spring-cloud-zookeeper.adoc index d036d380..5a44b87c 100644 --- a/docs/src/main/asciidoc/spring-cloud-zookeeper.adoc +++ b/docs/src/main/asciidoc/spring-cloud-zookeeper.adoc @@ -509,12 +509,38 @@ autoconfiguration that sets up Spring Cloud Zookeeper Config. CAUTION: When working with version 3.4 of Zookeeper you need to change the way you include the dependency as described <>. +[[config-data-import]] +=== Spring Boot Config Data Import + +Spring Boot 2.4 introduced a new way to import configuration data via the `spring.config.import` property. This is now the default way to get configuration from Zookeeper. + +To optionally connect to Zookeeper for configuration set the following in application.properties: + +.application.properties +[source,properties] +---- +spring.config.import=optional:zookeeper: +---- + +This will connect to Zookeeper at the default location of "localhost:2181". Removing the `optional:` prefix will cause Zookeeper Config to fail if it is unable to connect to Zookeeper. To change the connection properties of Zookeeper Config either set `spring.cloud.zookeeper.connect-string` or add the connect string to the `spring.config.import` statement such as, `spring.config.import=optional:zookeeper:myhost:2818`. The location in the import property has precedence over the `connect-string` property. + +Zookeeper Config will try to load values from four automatic contexts based on `spring.cloud.zookeeper.config.name` (which defaults to the value of the `spring.application.name` property) and `spring.cloud.zookeeper.config.default-context` (which defaults to `application`). If you want to specify the contexts rather than using the computed ones, you can add that information to the `spring.config.import` statement. + +.application.properties +[source,properties] +---- +spring.config.import=optional:zookeeper:myhost:2181/contextone;/context/two +---- + +This will optionally load configuration only from `/contextone` and `/context/two`. + +NOTE: A `bootstrap` file (properties or yaml) is *not* needed for the Spring Boot Config Data method of import via `spring.config.import`. + === Customizing Zookeeper Config may be customized by setting the following properties: [source,yml,indent=0] -.bootstrap.yml ---- spring: cloud: @@ -532,6 +558,8 @@ spring: * `profileSeparator`: Sets the value of the separator used to separate the profile name in property sources with profiles. +CAUTION: If you have set `spring.cloud.bootstrap.enabled=true` or `spring.config.use-legacy-processing=true`, or included `spring-cloud-starter-bootstrap`, then the above values will need to be placed in `bootstrap.yml` instead of `application.yml`. + === Access Control Lists (ACLs) You can add authentication information for Zookeeper ACLs by calling the `addAuthInfo`