3

I am getting the following error for a bean in my application context:

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'businessLogicContext' d efined in class path resource [activemq-jms-consumer.xml]: Unsatisfied dependency expressed through constructor argument  with index 0 of type [java.lang.String]: Could not convert constructor argument value of type [java.util.ArrayList] to required type [java.lang.String]: Failed to convert value of type [java.util.ArrayList] to required type [java.lang.Stri ng]; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to requi red type [java.lang.String]: no matching editors or conversion strategy found
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:53 4)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:18 6)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAuto wireCapableBeanFactory.java:855)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutow ireCapableBeanFactory.java:765)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCap ableBeanFactory.java:412)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBea nFactory.java:383)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapab leBeanFactory.java:353)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegis try.java:169)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListable BeanFactory.java:400)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplic ationContext.java:736)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java :123)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java :66)

Here is my bean:

<bean id="businessLogicContext" class="org.springframework.context.support.ClassPathXmlApplicationContext" depends-on="resolveProperty">
         <constructor-arg index="0">
            <list>
               <value>jms-applicationContext.xml</value>
               <value>jms-managerBeanContext.xml</value>
               <value>jms-daoContext.xml</value>
               <value>jms-serviceContext.xml</value>
          </list>       
         </constructor-arg>
    </bean>

I don't know what's wrong, I have googled how to inject a string array via constructor injection and the way I do it above seems okay.

1
  • Cannot reproduce - ClassPathXmlApplicationContext can be sucessfully constructed using this syntax Commented Dec 22, 2010 at 17:52

4 Answers 4

1

The constructor expects a String or String[] type and you're attempting to inject an ArrayList.

Sign up to request clarification or add additional context in comments.

1 Comment

Spring can normally handle coercing a list into an array just fine. This class has rather complicated constructors, though, and it's getting confused.
1

Make it like this

<bean id="businessLogicContext" class="org.springframework.context.support.ClassPathXmlApplicationContext" depends-on="resolveProperty">
         <constructor-arg>
            <list>
               <value>jms-applicationContext.xml</value>
               <value>jms-managerBeanContext.xml</value>
               <value>jms-daoContext.xml</value>
               <value>jms-serviceContext.xml</value>
          </list>       
         </constructor-arg>
    </bean>    

Check the constructor doc It accepts array of String, which can be injected using <list>

4 Comments

Will it implicitly convert a list type to an array type?
@javamonkey79: It should do, yes
@javamonkey79 Check the [constructor doc](static.springsource.org/spring/docs/2.5.x/api/org/… It accepts array of String, which can be injected using <list>
@Jeune It should work, can you post updated error message in Question
0

You can try this:

<bean id="businessLogicContext" class="org.springframework.context.support.ClassPathXmlApplicationContext" depends-on="resolveProperty">
   <constructor-arg value="jms-applicationContext.xml,jms-managerBeanContext.xml,jms-daoContext.xml,jms-serviceContext.xml"/>
</bean>

Comments

0

I accidentally overwrote a certain jar --- xbean.jar with a different version from the one I was previously using.

So when I compiled my jar with this different version as dependency and ran it it was giving me this error. It's working now. hehe.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.