You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/appendix-configuration-metadata.adoc
+71-32Lines changed: 71 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -695,6 +695,11 @@ The following metadata snippet corresponds to the standard `spring.profiles.acti
695
695
== Generating Your Own Metadata by Using the Annotation Processor
696
696
You can easily generate your own configuration metadata file from items annotated with `@ConfigurationProperties` by using the `spring-boot-configuration-processor` jar.
697
697
The jar includes a Java annotation processor which is invoked as your project is compiled.
To use the processor, include a dependency on `spring-boot-configuration-processor`.
699
704
700
705
With Maven the dependency should be declared as optional, as shown in the following example:
@@ -759,20 +764,73 @@ If you are using an `additional-spring-configuration-metadata.json` file, the `c
759
764
760
765
This dependency ensures that the additional metadata is available when the annotation processor runs during compilation.
761
766
762
-
The processor picks up both classes and methods that are annotated with `@ConfigurationProperties`.
763
-
The Javadoc for field values within configuration classes is used to populate the `description` attribute.
767
+
[NOTE]
768
+
====
769
+
If you are using AspectJ in your project, you need to make sure that the annotation processor runs only once.
770
+
There are several ways to do this.
771
+
With Maven, you can configure the `maven-apt-plugin` explicitly and add the dependency to the annotation processor only there.
772
+
You could also let the AspectJ plugin run all the processing and disable annotation processing in the `maven-compiler-plugin` configuration, as follows:
764
773
765
-
NOTE: You should only use plain text with `@ConfigurationProperties` field Javadoc, since they are not processed before being added to the JSON.
If the class has a single constructor with at least one parameters, one property is created per constructor parameter.
768
-
Otherwise, properties are discovered through the presence of standard getters and setters with special handling for collection types (that is detected even if only a getter is present).
The processor picks up both classes and methods that are annotated with `@ConfigurationProperties`.
791
+
792
+
If the class is also annotated with `@ConstructorBinding`, a single constructor is expected and one property is created per constructor parameter.
793
+
Otherwise, properties are discovered through the presence of standard getters and setters with special handling for collection and map types (that is detected even if only a getter is present).
770
794
The annotation processor also supports the use of the `@Data`, `@Getter`, and `@Setter` lombok annotations.
771
795
772
-
The annotation processor cannot auto-detect default values for ``Enum``s and ``Collections``s.
773
-
In the cases where a `Collection` or `Enum` property has a non-empty default value, <<configuration-metadata-additional-metadata,manual metadata>> should be provided.
796
+
Consider the following example:
797
+
798
+
[source,java,indent=0,subs="verbatim,attributes"]
799
+
----
800
+
@ConfigurationProperties(prefix="server")
801
+
public class ServerProperties {
802
+
803
+
/**
804
+
* Name of the server.
805
+
*/
806
+
private String name;
807
+
808
+
/**
809
+
* IP address to listen to.
810
+
*/
811
+
private String ip = "127.0.0.1";
812
+
813
+
/**
814
+
* Port to listener to.
815
+
*/
816
+
private int port = 9797;
817
+
818
+
// ... getter and setters
819
+
820
+
}
821
+
----
822
+
823
+
This exposes three properties where `server.name` has no default and `server.ip` and `server.port` defaults to `"127.0.0.1"` and `9797` respectively.
824
+
The Javadoc on fields is used to populate the `description` attribute. For instance, the description of `server.ip` is "IP address to listen to.".
774
825
775
-
Consider the following class:
826
+
NOTE: You should only use plain text with `@ConfigurationProperties` field Javadoc, since they are not processed before being added to the JSON.
827
+
828
+
The annotation processor applies a number of heuristics to extract the default value from the source model.
829
+
Default values have to be provided statically. In particular, do not refer to a constant defined in another class.
830
+
Also, the annotation processor cannot auto-detect default values for ``Enum``s and ``Collections``s.
831
+
832
+
For cases where the default value could not be detected, <<configuration-metadata-additional-metadata,manual metadata>> should be provided.
@@ -811,33 +869,14 @@ In order to document default values for properties in the class above, you could
811
869
]}
812
870
----
813
871
814
-
Only the `name` of the property is required to document additional fields with manual metadata.
815
-
816
-
[NOTE]
817
-
====
818
-
If you are using AspectJ in your project, you need to make sure that the annotation processor runs only once.
819
-
There are several ways to do this.
820
-
With Maven, you can configure the `maven-apt-plugin` explicitly and add the dependency to the annotation processor only there.
821
-
You could also let the AspectJ plugin run all the processing and disable annotation processing in the `maven-compiler-plugin` configuration, as follows:
0 commit comments