I've seen tutorials where they use different syntax to accomplish the same thing. Once a POST request to create a student object comes in via the controller, the service layer injects the repository using these two methods.
method 1:
@Service
@AllArgsConstructor
@Transactional
public class StudentService {
private final StudentRepository studentRepo;
// complete service code using studentRepo
}
As well as Method 2:
@Service
public class StudentService {
@Autowire
private StudentRepository studentRepo;
// complete service code using studentRepo
}
I read that it has something to do with constructor and field injection but I'm seriously not understanding how this syntax addresses the difference. Any explanations or resources for me to better understand? Thank you in advance!