1
@ConfigurationProperties
クラスのプロパティのいずれかが不足している場合、起動時にSpring-Bootを失敗させる方法を教えてください。プロパティが見つからない場合、Springブートが失敗しない
@Value(...)
を代わりに使用すると、自動配線が正常に機能しませんが、@Value
の参照をアプリケーションで使用する代わりに、すべてのプロパティを@ConfigurationProperties
クラスに集中したいとします。
コード:
@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;
}
}