我有这个 Lombok 类,但在创建该类时未注入(inject)值
@Data
@Builder
@Component
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
public class Task {
@org.springframework.beans.factory.annotation.Value("${timeInMinutes}")
private @NotNull Integer timeInMinutes;
最佳答案
如果您想从应用程序属性中获取值,请使用自定义构造函数而不是使用注释 @AllArgsConstructor。
public class Task {
private Integer timeInMinutes;
Task(@Value("${timeInMinutes}") Integer timeInMinutes){
this.timeInMinutes = timeInMinutes;
}
}
关于java - Lombok 具有配置中的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61249827/