File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
spring-boot-docs/src/main/asciidoc Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -781,6 +781,35 @@ annotations to your `@ConfigurationProperties` class:
781
781
}
782
782
----
783
783
784
+
785
+ In order to validate values of nested properties, you must annotate the associated field
786
+ as `@Valid` to trigger its validation. For example, building upon the above
787
+ `ConnectionSettings` example:
788
+
789
+ [source,java,indent=0]
790
+ ----
791
+ @Component
792
+ @ConfigurationProperties(prefix="connection")
793
+ public class ConnectionSettings {
794
+
795
+ @NotNull
796
+ @Valid
797
+ private RemoteAddress remoteAddress;
798
+
799
+ // ... getters and setters
800
+
801
+ private static class RemoteAddress {
802
+
803
+ @NotEmpty
804
+ public String hostname;
805
+
806
+ // ... getters and setters
807
+
808
+ }
809
+
810
+ }
811
+ ----
812
+
784
813
You can also add a custom Spring `Validator` by creating a bean definition called
785
814
`configurationPropertiesValidator`. There is a
786
815
{github-code}/spring-boot-samples/spring-boot-sample-property-validation[Validation sample]
You can’t perform that action at this time.
0 commit comments