Let's say I have the following constructor injection (not Autowiring):
@Service
public class FooService {
private final OrderService orderService;
public FooService(OrderService orderService) {
this.orderService = orderService;
}
}
That can be replaced with:
@Service
@AllArgsConstructor
public class FooService {
private final OrderService orderService;
}
Do I need to declare this as private
and final
to inject this service? Does Lombok take care of this like they do with @Data
and beans? Any side-effects?
According to documentation
@AllArgsConstructor
generates a constructor with 1 parameter for each field in your class. Fields marked with@NonNull
result in null checks on those parameters.
So, no, it does not make your fields private
& final
as for example @Value
annotation.