santhosh
santhosh

Reputation: 53

How does IoC create instances for beans

I learned that when IoC container initializes, it creates instances and injects the dependencies.

How does it create the objects? Is it creating them using the new operator?

Upvotes: 2

Views: 1544

Answers (2)

Atul
Atul

Reputation: 2711

1 Classes if they have a non-private constructor defined and same is declared in configuration metadata, are instantiated using reflection. getDeclaredConstructor() of a class API

  1. Some classes are instantiated using the static or non static factory methods if defined in the metadata.

Please read section 4.3.2 Instantiating beans from spring documentation

Upvotes: 0

Ralph
Ralph

Reputation: 120781

In Java the only way to instanciate an object, is to call a constructor. You can call the constructor using the new operator or by reflection.

Spring use reflection to instanciate an object.

Upvotes: 2

Related Questions