How does autowiring work in Spring?

后端 未结 11 1571
执笔经年
执笔经年 2020-11-22 15:35

I\'m a little confused as to how the inversion of control (IoC) works in Spring.

Say I have a service class called UserServic

11条回答
  •  情深已故
    2020-11-22 16:15

    How does @Autowired work internally?

    Example:

    class EnglishGreeting {
       private Greeting greeting;
       //setter and getter
    }
    
    class Greeting {
       private String message;
       //setter and getter
    }
    

    .xml file it will look alike if not using @Autowired:

    
       
    
    
    
       
    
    

    If you are using @Autowired then:

    class EnglishGreeting {
       @Autowired //so automatically based on the name it will identify the bean and inject.
       private Greeting greeting;
       //setter and getter
    }
    

    .xml file it will look alike if not using @Autowired:

    
    
    
       
    
    

    If still have some doubt then go through below live demo

    How does @Autowired work internally ?

提交回复
热议问题