Sandro Rey
Sandro Rey

Reputation: 2989

Lombok with default value from config

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

Answers (1)

Mamtha Soni K
Mamtha Soni K

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

Related Questions