To get dependencies automatically inject in the required class without declaring them as a property (setter injection) or constructor-args (constructor injection), this autowire attribute can be used in the bean.
<\bean class="com.inc.arun.Myclass" id="mybean" autowire="byName">
<\/bean>
<\bean class="com.inc.arun.Myclass2" id="mybean2">
Now, Myclass is using the object of Myclass2 and is declared as a field therein. But in my configuration file I have not declared it as a property. It will be automaticall looked for the name with which Myclass2 is declared in Myclass. As the bean declaration for Myclass2 have id as 'mybean2' so in Myclass the object my Myclass2 should have the same attribute name.
Other ways of autowiring is byType, constructor, autodetect. byType work on the basis of Type of the object declared in the required class. It has a limitation in case of interface type declaration. Similarly constructor autowiring is based on the types and parameters of constructor and its limitation is that only one constructor cab be declared.
No comments:
Post a Comment