Announcement Announcement Module
Collapse
No announcement yet.
[Solved] Trouble converting a String at bean creation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Solved] Trouble converting a String at bean creation

    Hi !
    I've got quite a strange problem. Here is my xml config file :

    Code:
    <bean id="Datasource" class="com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl">
    <constructor-arg index="0">
    <value>datasource.xml</value>
    </constructor-arg>
    </bean>
    Basicly my bean requires a String to be created, here my string is "datasource.xml".

    Code:
    public XmlDbImpl&#40;String datafile&#41; 
    &#123;
    	this.datafile = datafile;	
    &#125;
    However, at run time i got this :

    Code:
    2005-08-16 13&#58;44&#58;34 StandardContext&#91;/phonebook&#93;Exception lors de l'envoi de l'évènement contexte initialisé &#40;context initialized&#41; à l'instance de classe d'écoute &#40;listener&#41; org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.UnsatisfiedDependencyException&#58; Error creating bean with name 'Dao' defined in class path resource &#91;org/springframework/webflow/samples/phonebook/deploy/service-layer.xml&#93;&#58; Unsatisfied dependency expressed through constructor argument with index 0 of type &#91;java.lang.String&#93;&#58; Could not convert constructor argument value &#91;[email protected]346a3&#93; to required type &#91;java.lang.String&#93;&#58; Failed to convert property value of type &#91;com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl&#93; to required type &#91;java.lang.String&#93;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createArgumentArray&#40;AbstractAutowireCapableBeanFactory.java&#58;697&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor&#40;AbstractAutowireCapableBeanFactory.java&#58;584&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;312&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;226&#41;

  • #2
    You posted the definition of a "Datasource" bean. The error message, however, is about a "Dao" bean.

    There you seem to expect a String but you provide a XmlDbImpl instance.

    Regards,
    Andreas

    Comment


    • #3
      Sorry ! My fault !

      Here is the complete config :


      Code:
      <bean id="Datasource" class="com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl">
      			<constructor-arg index="0"><value>datasource</value></constructor-arg>
      		</bean>
      			
      		<bean id="Dao" class="com.ao.springframework.webflow.samples.phonebook.doa.XmlDao">
      			<constructor-arg><ref bean="Datasource"/></constructor-arg>
      		</bean>

      Comment


      • #4
        Please check the XmlDao constructor. Which kind of argument does it expect? From the error message it should be a String.

        If you have multiple constructors, maybe you should specify index="0" for the constructor-arg element to resolve ambiguities.

        Regards,
        Andreas

        Comment


        • #5
          I tried this only alone :

          Code:
          	<bean id="Datasource" class="com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl">
          			<constructor-arg index="0"><value>datasource</value></constructor-arg>
          		</bean>
          So it basicly mean that this bean is properly created, so it's not a converting problem related to this String.

          I do not have multiple constructor, i tried with index 0, and i got :

          Code:
          2005-08-16 15&#58;48&#58;58 StandardContext&#91;/phonebook&#93;Exception lors de l'envoi de l'évènement contexte initialisé &#40;context initialized&#41; à l'instance de classe d'écoute &#40;listener&#41; org.springframework.web.context.ContextLoaderListener
          org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'phoneBook' defined in class path resource &#91;org/springframework/webflow/samples/phonebook/deploy/service-layer.xml&#93;&#58; Can't resolve reference to bean 'Dao' while setting property 'constructor argument with index 0'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException&#58; Error creating bean with name 'Dao' defined in class path resource &#91;org/springframework/webflow/samples/phonebook/deploy/service-layer.xml&#93;&#58; Unsatisfied dependency expressed through constructor argument with index 0 of type &#91;java.lang.String&#93;&#58; Could not convert constructor argument value &#91;[email protected]e4cd&#93; to required type &#91;java.lang.String&#93;&#58; Failed to convert property value of type &#91;com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl&#93; to required type &#91;java.lang.String&#93;
          or
          So it keeps trying to convert my bean into a String... ( or the opposite).

          However, my config seems ok, isn't it ?

          Code:
          	<bean id="Datasource" class="com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl">
          			<constructor-arg index="0"><value>datasource</value></constructor-arg>
          		</bean>
          
          		<bean id="phoneBook" class="com.ao.springframework.webflow.samples.phonebook.doa.PhoneBookImpl">
          			<constructor-arg index="0"><ref bean="Dao"/></constructor-arg>
          		</bean> 
          				
          		<bean id="Dao" class="com.ao.springframework.webflow.samples.phonebook.doa.XmlDao">
          			<constructor-arg index="0"><ref bean="Datasource"/></constructor-arg>
          		</bean>

          Comment


          • #6
            Originally posted by belaran
            Code:
            	<bean id="Datasource" class="com.ao.springframework.webflow.samples.phonebook.orm.XmlDbImpl">
            			<constructor-arg index="0"><value>datasource</value></constructor-arg>
            		</bean>
            The problem is not the bean with the id "Datasource". It's the bean with the name Dao.

            Please check the constructor(s) of type com.ao.springframework.webflow.samples.phonebook.d oa.XmlDao. According to the error this type has no constructor which takes a single argument of type "com.ao.springframework.webflow.samples.phonebook. orm.XmlDbImpl" which you try to pass in.

            Regards,
            Andreas

            Comment


            • #7
              Thanks you put me in the good direction !

              I was looking for something wrong in my config ( such missing index="0") but in fact the problem was there : I refactored my class XmlDao to DaoImpl so it couldn't find the proper class !

              ( i know this is pretty silly)

              Thanks a lot !

              Comment

              Working...
              X