|
From: Rod J. <rod...@in...> - 2003-11-09 22:47:53
|
Juergen,
I'll look more closely at the details tomorrow, but this is very good news!
An important enhancement for M3.
I think that although we should continue to advocate JavaBeans ("Type 2") as
the best alternative in most cases, Type 3 is a good choice in a minority of
cases. And in any case, the Spring philosophy is to be non-intrusive. We
don't want to tell people how they should code.
Regards,
Rod
----- Original Message -----
From: "jürgen höller [werk3AT]" <jue...@we...>
To: <spr...@li...>
Sent: Sunday, November 09, 2003 9:47 PM
Subject: [Springframework-developer] Type 3 IoC support
Everybody,
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="constructor" for autowiring constructor arguments by
type, just like autowire="byType" does for bean properties.
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)!
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="constructor" or "constructor-arg" tags can still have any number
of constructors, the only requirement being that they must provide a no-arg
constructor.
As an example, the XML bean definition from the test case:
<beans>
<bean id="rod1"
class="org.springframework.beans.factory.xml.ConstructorDependenciesBean">
<constructor-arg><ref bean="other"/></constructor-arg>
<constructor-arg><ref bean="kerry2"/></constructor-arg>
</bean>
<bean id="rod2"
class="org.springframework.beans.factory.xml.ConstructorDependenciesBean">
<constructor-arg index="1"><ref bean="kerry1"/></constructor-arg>
<constructor-arg index="0"><ref bean="kerry2"/></constructor-arg>
<constructor-arg><ref bean="other"/></constructor-arg>
</bean>
<bean id="rod3"
class="org.springframework.beans.factory.xml.ConstructorDependenciesBean"
autowire="constructor">
<constructor-arg><ref bean="kerry2"/></constructor-arg>
</bean>
<bean id="rod4"
class="org.springframework.beans.factory.xml.DerivedConstructorDependenciesB
ean">
<constructor-arg index="1"><ref bean="kerry1"/></constructor-arg>
<constructor-arg index="3"><value>99</value></constructor-arg>
<constructor-arg><ref bean="other"/></constructor-arg>
<constructor-arg index="4"><value>myname</value></constructor-arg>
<constructor-arg index="0"><ref bean="kerry2"/></constructor-arg>
</bean>
<bean id="kerry1" class="org.springframework.beans.TestBean">
<property name="name">
<value>Kerry</value>
</property>
</bean>
<bean id="kerry2" class="org.springframework.beans.TestBean">
<property name="name">
<value>Kerry</value>
</property>
</bean>
<bean id="other" class="org.springframework.beans.factory.LifecycleBean"/>
</beans>
Juergen
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|