Reputation: 2989
I have this Lombok class but the values are not injected when I create the class
@Data
@Builder
@Component
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
public class Task {
@org.springframework.beans.factory.annotation.Value("${timeInMinutes}")
private @NotNull Integer timeInMinutes;
Upvotes: 0
Views: 1740
Reputation: 965
If you would want to fetch the value from application properties, Use a custom constructor instead of using the annotation @AllArgsConstructor.
public class Task {
private Integer timeInMinutes;
Task(@Value("${timeInMinutes}") Integer timeInMinutes){
this.timeInMinutes = timeInMinutes;
}
}
Upvotes: 3