|
From: <jue...@we...> - 2003-11-10 17:48:48
|
As a side note, you cannot combine autowire "byName" and "byType" = either, although that would technically be possible - both just resolve = what they are able to and ignore the rest. It just doesn't make sense to = mix those autowiring styles, as it can lead to quite unpredictable = behavior. If you've got special requirements, explicit references are = the better choice - you can activate a certain autowiring style by = default and just override specific properties, for example. Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of j=FCrgen h=F6ller [werk3AT] Sent: Monday, November 10, 2003 5:44 PM To: spr...@li... Subject: RE: [Springframework-developer] Type 3 IoC support Autowiring both constructor arguments and bean properties is a bit = awkward. Either you resolve dependencies of a certain bean via a = constructor or via bean properties - but not both ways, especially if = autowiring. For example, a bean might contain a constructor with a = DataSource argument and a bean property of type DataSource - but doesn't = expect to get passed both, as they are just alternative means of setting = its DataSource. When specifying direct references via "constructor-arg" and "property", = you can of course pass certain dependencies into the constructor and = other ones into bean properties. This way, you won't experience side = effects of double setting etc as in the = autowiring-both-constructors-and-properties case. With direct = references, you should be able to apply any kind of = constructor/properties combination. Finally, as you assume, "constructor-arg" tags will be applied before = autowiring - just like "property" tags. The exact order for resolving a = constructor argument is: Indexed constructor argument value, generic = constructor argument value that matches by type, autowired value (if = activated). Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Alef Arendsen (JTeam) Sent: Sunday, November 09, 2003 11:22 PM To: spr...@li... Subject: RE: [Springframework-developer] Type 3 IoC support Hmm, this looks promising. I don't want to get to deep in the source now, so two basic questions (so I can immediately put this in the docs as well): I was wondering how multiple autowire types are supported. Is it possible to use both constructor autowiring and byType autowiring (in order to get both constructors have arguments as well as beanstyle setters)? Then, I assume any constructor arguments specified by a constructor-arg will not be included in the autowiring process? Alef > -----Oorspronkelijk bericht----- > Van: spr...@li...=20 > [mailto:spr...@li...] > Namens j=FCrgen h=F6ller [werk3AT] > Verzonden: Sunday, November 09, 2003 10:48 PM > Aan: spr...@li... > Onderwerp: [Springframework-developer] Type 3 IoC support >=20 >=20 > Everybody, > =20 > I'm pleased to announce that a Spring bean factory is now=20 > capable of handling Type 3 IoC components! As the most=20 > important feature, I've introduced autowire=3D"constructor" for=20 > autowiring constructor arguments by type, just like=20 > autowire=3D"byType" does for bean properties.=20 > =20 > Furthermore, there is a "constructor-arg" tag within the=20 > "bean" tag now, to pass specific beans or values to=20 > constructor arguments. "constructor-arg" can specify generic=20 > values that get matched by type, or values for a specific=20 > argument via its "index" attribute. This means that we can=20 > handle any kind of constructor, be it with bean references,=20 > simple values, lists, maps, etc. We can also easily handle=20 > multiple constructor arguments of the same type, i.e. 2=20 > DataSource arguments or 2 String values (in contrast to the=20 > current Pico version)! > =20 > The only limitation is that constructor-wired components are=20 > just allowed to have one single constructor. This is also=20 > what Pico recommends, although they have some heuristic kind=20 > of constructor choice in case of multiple constructors now. I=20 > guess we can limit this to one single constructor for the=20 > time being. Of course, standard beans defined without=20 > autowire=3D"constructor" or "constructor-arg" tags can still=20 > have any number of constructors, the only requirement being=20 > 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"=20 > class=3D"org.springframework.beans.factory.xml.ConstructorDepend > enciesBean"> > <constructor-arg><ref bean=3D"other"/></constructor-arg> > <constructor-arg><ref bean=3D"kerry2"/></constructor-arg> </bean> > =20 > <bean id=3D"rod2"=20 > class=3D"org.springframework.beans.factory.xml.ConstructorDepend > enciesBean"> > <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"=20 > class=3D"org.springframework.beans.factory.xml.ConstructorDepend > enciesBean" > autowire=3D"constructor"> > <constructor-arg><ref bean=3D"kerry2"/></constructor-arg> </bean> > =20 > <bean id=3D"rod4"=20 > class=3D"org.springframework.beans.factory.xml.DerivedConstructo > rDependenciesBean"> > <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=20 > 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"=20 > class=3D"org.springframework.beans.factory.LifecycleBean"/> > =20 > </beans> >=20 > Juergen >=20 >=20 > ------------------------------------------------------- > This SF.Net email sponsored by: ApacheCon 2003, > 16-19 November in Las Vegas. Learn firsthand the latest=20 > developments in Apache, PHP, Perl, XML, Java, MySQL, WebDAV,=20 > and more! http://www.apachecon.com/=20 > _______________________________________________ > Springframework-developer mailing list=20 > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer >=20 ------------------------------------------------------- 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 ------------------------------------------------------- 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 |