我有这种依赖性:
<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
班上有这样的香料:
@SpringBootApplication
@EnableConfigurationProperties
@ComponentScan({ "otherPackages", "packageWhereCollectorPropertiesIs" })
当我有application.properties
这条线时
collector.urlCDI=https://www.cetip.com.br/Home
它可以像在其他春豆中一样发挥作用:
//@Component class variables:
@Autowired
private CollectorProperties props;
//inside some method
URL url = new URL(props.getUrlCDI());
但是,当我删除它或更改属性键时,会得到很多NPE而不是验证错误。我做错了什么?不hibernate-validator
包含javax.validation.constraints.NotNull
接口的实现吗?
在您的媒体资源类中添加“ @Validated”注释
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句