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

16 lines
893 B
Markdown
Raw Normal View History

### 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)。