0

I work as a intern somewhere and they said you dont have to use autowired there. They said search for it but i couldnt good explanation about it.

public class MedicineController {
    
    private IMedicineService iMedicineService;
    
    //I used @Autowired here
    public MedicineController(IMedicineService iMedicineService) {
        this.iMedicineService = iMedicineService;
    }
kaganince1
  • 33
  • 9
  • Did you use @Autowired to annotate the parameter IMedicineService ? – Matteo NNZ Jul 27 '21 at 12:21
  • 1
    If you have only one constructor, there is no need to add @Autowired, spring will consider it as a required injection under the hood. – zawarudo Jul 27 '21 at 12:59
  • No i didnt use @Autowired in IMedicineService – kaganince1 Jul 27 '21 at 13:07
  • 1
    The version of Spring you are using is smart enough to understand that it should inject an `IMedicineService` bean automatically into your `MedicineController`. The `@Autowired` annotation is not necessary. (It used to be required here for older versions of Spring). – Jesper Jul 27 '21 at 13:44

0 Answers0