Document validation of nested components
See gh-3566
This commit is contained in:
committed by
Stephane Nicoll
parent
9244781493
commit
fbf6574b51
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user