|
From: Colin S. <col...@ex...> - 2003-11-15 13:48:03
|
Thanks Juergen. I actually did not have time to look at the Spring code yesterday, but just assumed the List to String[] match would work, since the DTD (explicitly) said a List to array conversion would be done automatically. Of course, conversion once matched, and the matching itself (in the new code) are not quie the same thing :-) I'll give the code a try later... jürgen höller [werk3AT] wrote: >Colin, > >The problem is that you tried to pass a <list> into a String[] constructor. The generic constructor argument matcher did not recognize that as compatible, therefore it continued with the next constructor. If you explicitly specified an index, the matching was not by type and therefore worked. > >I've just added a check to match an array argument with a List value, and also a unit test that instantiates a parent and child ClassPathXmlApplicationContext (without explicit indexes specified). > >The exception "2 constructor arguments specified but just constructor with 1 argument found" was a bit misleading, as it rather indicates "no matching constructor found" (with at least the given number of arguments). I've already changed its wording. > >So please grab the latest CVS snapshot and happily instantiate ClassPathXmlApplicationContexts for whatever reason :-) > >Juergen > > >________________________________ > >Von: spr...@li... im Auftrag von Colin Sampaleanu >Gesendet: Fr 14.11.2003 23:55 >An: spr...@li... >Betreff: Re: [Springframework-developer] Type 3 IoC support > > > >There is definitely an issue. When trying to use the two argument >constructor, of which there is only one, I get > >; nested exception is: > org.springframework.beans.factory.BeanDefinitionStoreException: 2 >constructor arguments specified but just constructor with 1 arguments >found in bean 'packaging-context' >org.springframework.beans.factory.BeanDefinitionStoreException: 2 >constructor arguments specified but just constructor with 1 arguments >found in bean 'packaging-context' > at >org.springframework.beans.factory.support.AbstractBeanFactory.autowireConstructor(AbstractBeanFactory.java:444) > at >org.springframework.beans.factory.support.AbstractBeanFactory.createBean(AbstractBeanFactory.java:352) > at >org.springframework.beans.factory.support.AbstractBeanFactory.getSharedInstance(AbstractBeanFactory.java:274) > at >org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:203) > at >org.springframework.beans.factory.support.AbstractBeanFactory.resolveReference(AbstractBeanFactory.java:717) > at >org.springframework.beans.factory.support.AbstractBeanFactory.resolveValueIfNecessary(AbstractBeanFactory.java:688) > at >org.springframework.beans.factory.support.AbstractBeanFactory.autowireConstructor(AbstractBeanFactory.java:418) > at >org.springframework.beans.factory.support.AbstractBeanFactory.createBean(AbstractBeanFactory.java:352) > at >org.springframework.beans.factory.support.AbstractBeanFactory.getSharedInstance(AbstractBeanFactory.java:274) > at >org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:203) > at >org.springframework.beans.factory.support.AbstractBeanFactory.resolveReference(AbstractBeanFactory.java:717) > at >org.springframework.beans.factory.support.AbstractBeanFactory.resolveValueIfNecessary(AbstractBeanFactory.java:688) > at >org.springframework.beans.factory.support.AbstractBeanFactory.autowireConstructor(AbstractBeanFactory.java:418) > at >org.springframework.beans.factory.support.AbstractBeanFactory.createBean(AbstractBeanFactory.java:352) > at >org.springframework.beans.factory.support.AbstractBeanFactory.getSharedInstance(AbstractBeanFactory.java:274) > at >org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:203) > at >org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:468) > at >org.springframework.context.support.AbstractApplicationContext.preInstantiateSingletons(AbstractApplicationContext.java:354) > at >org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:240) > >However, if I add index="0" and index="1" respectively, to the two >constructor arguments, then it has no problem constructing it. Now my >understanding is that the indexes shouldn't be necessary in this >(non-ambiguous) case. > >Again, I'll probably be able to look at this on Mon. or Tues. if nobody >else has by then. > >Regards, >Colin > > >Colin Sampaleanu wrote: > > > >>Juergen, >> >>I think the constructor resolution may not be quite right. The >>following bean entry fails: >> <bean id="data-access-context" >> >>class="org.springframework.context.support.ClassPathXmlApplicationContext"> >> >> <constructor-arg> >> <list><value>/data-access-applicationContext.xml</value></list> >> </constructor-arg> >> </bean> >>with >> ... >> >>org.springframework.beans.factory.UnsatisfiedDependencyException: Bean w >>ith name 'data-access-context' has an unsatisfied dependency expressed >>through c >>onstructor argument with index 0 of type [java.lang.String] >> >>Where it should be able to resolve to the constructor which takes an >>array of Strings. Now I will probably look into this myself later, but >>wanted to give you a heads up in case you know offhand what the >>problem is. For the time being, I am in a hurry, and will just feed >>the one string I need to the constructor which takes one string. >> >>As to why I am trying to construct a context inside a context, I am >>doing some interesting coding; we can get into that later when >>everything is working :-) >> >> |