【发布时间】:2018-11-07 08:24:25
【问题描述】:
这是关于Spring Boot 的应用程序。如果有人配置了错误的Yaml file,我想在开始时检查并通知用户。我想问你们中的一些人,
- 这是实现它的正确方法吗?
-
RuntimeException是正确的选择吗? - 我是否正确使用了
lombok注释?
谢谢
@Component
@ConfigurationProperties
@Data
@NoArgsConstructor
public class ApplicationProperties{
@Data
@NoArgsConstructor
public static class Something {
private String name;
@Setter(AccessLevel.NONE)
private int width;
@Setter(AccessLevel.NONE)
private int height;
public void setWidth(int width) throws Throwable {
if (0 > width || 100 < width) {
throw new RuntimeException("The width should be between 0 and 100.");
}
this.width = width;
}
public void setHeight(int height) throws Throwable {
if (0 > height || 250 < height) {
throw new RuntimeException("The height should be between 0 and 250.");
}
this.height = height;
}
}
}
【问题讨论】:
标签: spring-boot lombok