1
如何在启动过程中使Spring-Boot失败,如果缺少@ConfigurationProperties
类的任何属性?如果属性丢失,Spring Boot不会失败
如果我使用@Value(...)
代替,自动布线会按预期失败,但我想集中所有属性到@ConfigurationProperties
类中,而不是使用通过应用程序传播的@Value
引用。
代码:
@Component
@ConfigurationProperties(value = "serving.api", ignoreUnknownFields = false)
public class ApplicationProperties {
private String projectId;
private String bigTableInstanceId;
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getBigTableInstanceId() {
return bigTableInstanceId;
}
public void setBigTableInstanceId(String bigTableInstanceId) {
this.bigTableInstanceId = bigTableInstanceId;
}
}