Announcement Announcement Module
Collapse
No announcement yet.
doubt on constructor injection with @Autowired annotation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • doubt on constructor injection with @Autowired annotation

    Hi,

    We can annotiate a constructor with @Autowired annotation. Now, a constructor is called while instantiating the object.

    But @Autowired is a BeanPostProcessor which is invoked after instantiation of object. Then how does Spring provide constructor injection with @Autowired annotiation.

    Please if someone can explain....?

    Regards,
    Jubin

  • #2
    Before creating Spring bean object instances, first it will create the order in which bean objects need to create. (like tree structure and all leaf beans will not have any dependencies and the container will create bean object instance for beans that have no dependencies. Hence when you have constructor dependency injection, those dependency beans objects have already created in the container and hence constructor Autowired dependency injection will go thru fine.

    Hope this helps.

    Comment

    Working...
    X