管理
<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
接口的实现?
add´@quarted'对您的属性class的注释
在控制器中使用Jakarta
@Validated