|
From: <jue...@we...> - 2003-11-09 21:50:15
|
Everybody, =20 I'm pleased to announce that a Spring bean factory is now capable of = handling Type 3 IoC components! As the most important feature, I've = introduced autowire=3D"constructor" for autowiring constructor arguments = by type, just like autowire=3D"byType" does for bean properties.=20 =20 Furthermore, there is a "constructor-arg" tag within the "bean" tag now, = to pass specific beans or values to constructor arguments. = "constructor-arg" can specify generic values that get matched by type, = or values for a specific argument via its "index" attribute. This means = that we can handle any kind of constructor, be it with bean references, = simple values, lists, maps, etc. We can also easily handle multiple = constructor arguments of the same type, i.e. 2 DataSource arguments or 2 = String values (in contrast to the current Pico version)! =20 The only limitation is that constructor-wired components are just = allowed to have one single constructor. This is also what Pico = recommends, although they have some heuristic kind of constructor choice = in case of multiple constructors now. I guess we can limit this to one = single constructor for the time being. Of course, standard beans defined = without autowire=3D"constructor" or "constructor-arg" tags can still = have any number of constructors, the only requirement being that they = must provide a no-arg constructor. =20 As an example, the XML bean definition from the test case: =20 <beans> =20 <bean id=3D"rod1" = class=3D"org.springframework.beans.factory.xml.ConstructorDependenciesBea= n"> <constructor-arg><ref bean=3D"other"/></constructor-arg> <constructor-arg><ref bean=3D"kerry2"/></constructor-arg> </bean> =20 <bean id=3D"rod2" = class=3D"org.springframework.beans.factory.xml.ConstructorDependenciesBea= n"> <constructor-arg index=3D"1"><ref bean=3D"kerry1"/></constructor-arg> <constructor-arg index=3D"0"><ref bean=3D"kerry2"/></constructor-arg> <constructor-arg><ref bean=3D"other"/></constructor-arg> </bean> =20 <bean id=3D"rod3" = class=3D"org.springframework.beans.factory.xml.ConstructorDependenciesBea= n" autowire=3D"constructor"> <constructor-arg><ref bean=3D"kerry2"/></constructor-arg> </bean> =20 <bean id=3D"rod4" = class=3D"org.springframework.beans.factory.xml.DerivedConstructorDependen= ciesBean"> <constructor-arg index=3D"1"><ref bean=3D"kerry1"/></constructor-arg> <constructor-arg index=3D"3"><value>99</value></constructor-arg> <constructor-arg><ref bean=3D"other"/></constructor-arg> <constructor-arg index=3D"4"><value>myname</value></constructor-arg> <constructor-arg index=3D"0"><ref bean=3D"kerry2"/></constructor-arg> </bean> =20 <bean id=3D"kerry1" class=3D"org.springframework.beans.TestBean"> <property name=3D"name"> <value>Kerry</value> </property> </bean> =20 <bean id=3D"kerry2" class=3D"org.springframework.beans.TestBean"> <property name=3D"name"> <value>Kerry</value> </property> </bean> =20 <bean id=3D"other" = class=3D"org.springframework.beans.factory.LifecycleBean"/> =20 </beans> Juergen |