2

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?

4

2 に答える 2

2

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.

于 2012-10-17T11:19:23.467 に答える
0

1非プライベートコンストラクターが定義されていて、同じものが構成メタデータで宣言されている場合、クラスはリフレクションを使用してインスタンス化されます。getDeclaredConstructor()クラス APIの

  1. 一部のクラスは、メタデータで定義されている場合、静的または非静的ファクトリメソッドを使用してインスタンス化されます。

セクション4.3.2SpringドキュメントからのBeanのインスタンス化をお読みください

于 2012-10-17T11:45:08.047 に答える