How does autowiring work in Spring?

后端 未结 11 1573
执笔经年
执笔经年 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条回答
  •  萌比男神i
    2020-11-22 16:28

    In simple words Autowiring, wiring links automatically, now comes the question who does this and which kind of wiring. Answer is: Container does this and Secondary type of wiring is supported, primitives need to be done manually.

    Question: How container know what type of wiring ?

    Answer: We define it as byType,byName,constructor.

    Question: Is there are way we do not define type of autowiring ?

    Answer: Yes, it's there by doing one annotation, @Autowired.

    Question: But how system know, I need to pick this type of secondary data ?

    Answer: You will provide that data in you spring.xml file or by using sterotype annotations to your class so that container can themselves create the objects for you.

提交回复
热议问题