@@ -8403,16 +8403,55 @@ assume that you are creating a starter for "acme" and that you name the auto-con
8403
8403
module `acme-spring-boot-autoconfigure` and the starter `acme-spring-boot-starter`. If
8404
8404
you only have one module that combines the two, name it `acme-spring-boot-starter`.
8405
8405
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
8407
8411
particular, do not include your keys in the namespaces that Spring Boot uses (such as
8408
8412
`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.
8410
8448
8411
8449
Make sure to
8412
8450
<<appendix-configuration-metadata#configuration-metadata-annotation-processor,trigger
8413
8451
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.
8416
8455
8417
8456
8418
8457
0 commit comments