Skip to content

Commit 30fe106

Browse files
committed
Improve how to configure configuration keys of a custom starter
Closes gh-17573
1 parent 300f07b commit 30fe106

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8403,16 +8403,55 @@ assume that you are creating a starter for "acme" and that you name the auto-con
84038403
module `acme-spring-boot-autoconfigure` and the starter `acme-spring-boot-starter`. If
84048404
you only have one module that combines the two, name it `acme-spring-boot-starter`.
84058405

8406-
Also, if your starter provides configuration keys, use a unique namespace for them. In
8406+
8407+
8408+
[[boot-features-custom-starter-configuration-keys]]
8409+
==== Configuration keys
8410+
If your starter provides configuration keys, use a unique namespace for them. In
84078411
particular, do not include your keys in the namespaces that Spring Boot uses (such as
84088412
`server`, `management`, `spring`, and so on). If you use the same namespace, we may modify
8409-
these namespaces in the future in ways that break your modules.
8413+
these namespaces in the future in ways that break your modules. As a rule of thumb,
8414+
prefix all your keys with a namespace that you own (e.g. `acme`).
8415+
8416+
Make sure that configuration keys are documented by adding field javadoc for each
8417+
property, as shown in the following example:
8418+
8419+
[source,java,indent=0]
8420+
----
8421+
@ConfigurationProperties("acme")
8422+
public class AcmeProperties {
8423+
8424+
/**
8425+
* Whether to check the location of acme resources.
8426+
*/
8427+
private boolean checkLocation = true;
8428+
8429+
/**
8430+
* Timeout for establishing a connection to the acme server.
8431+
*/
8432+
private Duration loginTimeout = Duration.ofSeconds(3);
8433+
8434+
// getters & setters
8435+
8436+
}
8437+
----
8438+
8439+
Here are some rules we follow internally to make sure descriptions are consistent:
8440+
8441+
* Do not start the description by "The" or "A".
8442+
* For `boolean` types, start the description with "Whether" or "Enable".
8443+
* For collection-based types, start the description with "Comma-separated list"
8444+
* Use `java.time.Duration` rather than `long` and describe the default unit if it differs
8445+
from milliseconds, e.g. "If a duration suffix is not specified, seconds will be used".
8446+
* Do not provide the default value in the description unless it has to be determined at
8447+
runtime.
84108448

84118449
Make sure to
84128450
<<appendix-configuration-metadata#configuration-metadata-annotation-processor,trigger
84138451
meta-data generation>> so that IDE assistance is available for your keys as well. You may
8414-
want to review the generated meta-data (`META-INF/spring-configuration-metadata.json`) to
8415-
make sure your keys are properly documented.
8452+
want to review the generated metadata (`META-INF/spring-configuration-metadata.json`) to
8453+
make sure your keys are properly documented. Using your own starter in a compatible IDE is
8454+
also a good idea to validate that quality of the metadata.
84168455

84178456

84188457

0 commit comments

Comments
 (0)