我有这样的依赖:
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>它的版本由
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>我有一段话:
import javax.validation.constraints.NotNull;
//other imports ommited
@Component
@ConfigurationProperties(prefix = "collector")
public class CollectorProperties {
@NotNull
private String urlCDI;
//getters and setters
}我的SpringApplication.run类有这个pice:
@SpringBootApplication
@EnableConfigurationProperties
@ComponentScan({ "otherPackages", "packageWhereCollectorPropertiesIs" })当我的application.properties包含这行代码时
collector.urlCDI=https://www.cetip.com.br/Home它在其他spring bean中的工作方式是:
//@Component class variables:
@Autowired
private CollectorProperties props;
//inside some method
URL url = new URL(props.getUrlCDI());但是当我删除它或者修改属性键时,我得到了很多NPE错误,而不是验证错误。我哪里做错了?hibernate-validator不包含javax.validation.constraints.NotNull接口的实现吗?
发布于 2018-08-14 09:21:42
向你的属性类添加“@Validated”注解
https://stackoverflow.com/questions/51832363
复制相似问题