有没有办法验证属性bean?
@Data
public class ProjectProperties {
@NotBlank
@NotEmpty
private String description;
}
使用以下命令创建bean:
@Bean
@ConfigurationProperties(prefix = "project")
@Valid
public ProjectProperties getProjectProperties() {
return new ProjectProperties();
}
和我的application.properties:
project.description =
是否有不同的方法使验证工作?
答案 0 :(得分:1)
@Data
@Validated
public class ProjectProperties {
@NotBlank
@NotEmpty
private String description;
}