spring_reference/IV. Spring Boot features/23.7.3. @ConfigurationPrope...

16 lines
893 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 23.7.3. @ConfigurationProperties校验
Spring Boot将尝试校验外部的配置默认使用JSR-303如果在classpath路径中。你可以轻松的为你的@ConfigurationProperties类添加JSR-303 javax.validation约束注解
```java
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {
@NotNull
private InetAddress remoteAddress;
// ... getters and setters
}
```
你也可以通过创建一个叫做configurationPropertiesValidator的bean来添加自定义的Spring Validator。
**注**spring-boot-actuator模块包含一个暴露所有@ConfigurationProperties beans的端点。简单地将你的web浏览器指向/configprops或使用等效的JMX端点。具体参考[Production ready features](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-endpoints)。