From fbf6574b5102d7b0aebe0f05ab827e89a4586deb Mon Sep 17 00:00:00 2001 From: drumonii Date: Mon, 20 Jul 2015 22:59:23 -0400 Subject: [PATCH] Document validation of nested components See gh-3566 --- .../main/asciidoc/spring-boot-features.adoc | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 87c76bee83..18c1e27a81 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -780,6 +780,32 @@ annotations to your `@ConfigurationProperties` class: } ---- +In order to validate values of nested properties, you must annotate the static nested +class as `@Valid`. For example, building upon the above `@ConfigurationProperties` class: + +[source,java,indent=0] +---- + @Component + @ConfigurationProperties(prefix="connection") + public class ConnectionSettings { + + @NotNull + @Valid + private InetAddress remoteAddress; + + // ... getters and setters + + private static class InetAddress { + + @NotEmpty + public String hostname; + + // ... getters and setters + + } + + } +---- You can also add a custom Spring `Validator` by creating a bean definition called `configurationPropertiesValidator`. There is a