Announcement Announcement Module
Collapse
No announcement yet.
Urgent: Error setting list from bean defined in XML config. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Urgent: Error setting list from bean defined in XML config.

    Hi

    I have a very urgent need to get the follwing bug fixed. Can you please help with the following?

    I have an XML config file which I pull in my application context, the

    XML bean entry is given below for reference. I have a java class
    TestConfig which sets the lists and gets the lists as defined in te config. file. As always the framework should go away and set the list for as per
    the definitions in the XML config file. Unfortunately spring has been unable to accept the defintion of the lists I've given. Please advise if my config XML is incorrect or if my class is not doing the setting/getting correctly.

    The entries for the class are given below as well.


    When I run my app I get the error below please help what am I doibg wrong!

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'TestConfig' defined in class path resource [beans-service-test.xml]: Can't resolve reference to bean 'CVB' while setting property 'convBonds[0]'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'CVB' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [instrumentDao,oracleDataSource,hibernateSessionFac tory,TestConfig]; Root of BeanFactory hierarchy

    XML File entries
    ------------------

    <bean id="TestConfig" class="com.services.testConfiguration">
    </property>
    <property name="convBonds">
    <list>
    <ref bean="CVB"/>
    <ref bean="CVP"/>
    </list>
    </property>
    <property name="altIds">
    <list>
    <ref bean="MC"/>
    <ref bean="SE"/>
    <ref bean="IS"/>
    <ref bean="RC"/>
    </list>
    </property>
    </bean>
    </beans>


    TestConfig Class
    --------------------


    /** Sets the convBonds
    * @param BigDecimal convBonds
    */
    public final void setconvBonds(final List convlist) {

    convBonds = convlist;

    }


    /** Sets the altIds
    * @param BigDecimal altIds
    */
    public final void setaltIds(final List altlist) {


    altIds = altlist;


    }




    /**
    * List of Bonds.
    */

    private List convBonds;

    /**
    * List of alt ids.
    */

    private List altIds;


    /** convBonds;
    *
    * @return convBonds;;
    */
    public final List convBonds() {
    return convBonds;
    }



    /**
    * altIds
    * @return altIds;
    */
    public final List altIds() {
    return altIds;
    }


  • #2
    aslam,

    Where in your config file did you declare beans CVB, CVP...
    When using <ref bean=""/> you are asking Spring to use a bean, that is already configured in an accessible config file, to set a property of an other bean.

    Omar.

    Comment


    • #3
      Hi Omar ASW,

      The XML code snippet I have provided is what Ihave defined to try and make this work.

      I have no other definitions for CVB, CVP... I thought that this was the correct way of letting Spring know that these are list items.

      CVB, CVP... and the others are only meant to be list items and not beans! can you please correct my XML code sippet and advise.

      Much obliged.

      Aslam

      Comment


      • #4
        I suppose CVB, CVP... are of type String
        Code:
        <bean id="TestConfig" class="com.services.testConfiguration"> 
          <property name="convBonds"> 
            <list> 
              <value>CVB</value> 
              <value>CVP</value> 
            </list> 
          </property> 
          <property name="altIds"> 
            <list> 
              <value>MC</value>
              <value>SE</value>
              <value>IS</value>
              <value>RC</value>
            </list> 
          </property> 
        </bean>
        HTH

        Comment


        • #5
          Hi

          Thanks for that, but unfortunately, Spring does not like the mutiple
          value enteries . I appreciate that we are saying <list>, but Spring is not accepting muti values in the list.

          However, with just one value Spring is accepting the list , but with mutiple values it is coming up with a multi value entry error.

          Comment


          • #6
            aslam,
            could you post the error log? b/w, what Spring version are you using?

            Comment


            • #7
              Omar,

              Unfortunately, I've come home after a long hard day and will be returning tommorrow (Saturday) as Ihave to get this done!. So regrettably, I do not have the output available for the attempt with mutiple values as per your suggestion.

              All I am trying to do is have a list of names (bond names) in a list
              which I can iterate through in my java. As the names can change often I was trying to set up a config java class and a XML config file to do the work as per Springs suggestion in "Registering additional custom PropertyEditors" there they only show a property with a single value which is manipulated via set and get in a java class.

              I can get it to work with single value , but I have a list of items as you can see in my code. Can you suggest how your code example may be tweaked to get Spring to accept the data as a java List ? I wil then try it out tommorow

              Many thanks for your help.

              Comment


              • #8
                Omar

                I think it's going to be something like this ('ve seen stuff on the web)


                <bean id="TestConfig" class="...">
                <property name="convBonds">
                <value>CVB,CVP</value>
                </property>
                </bean>

                Any idea how Spring would expect this to be held (java data type)?

                Many thanks.

                Comment


                • #9
                  This should work too, Spring will convert "CVB,CVP" into a java.util.List that contains two items of type java.lang.String

                  Comment


                  • #10
                    Omar,

                    Thanks, it's just what I need , hoefully it will do the trick, I'll try it out over the weekend and give you some feedback (least I can do for your kind assistence).


                    Have a good weekend.


                    Regards,

                    Aslam
                    8)

                    Comment


                    • #11
                      There's actually no reason Omar's original code sample shouldn't work either though. That's a valid way to define and set a list, with multiple values.

                      Comment


                      • #12
                        Hi

                        The list in XML is an ArrayList and needed to be mapped to a Arraylist
                        in the setter and getter methods.

                        Many thanks,

                        Aslam.

                        Comment


                        • #13
                          All,

                          Just wanted to clarify this post. The code that Omar demonstrated as the first solution will function just fine. When you need a List on one of your beans, then define a property of type List and use the <list> element in the XML configuration. The actual implementation that Spring uses may change so you shouldn't rely on a particular type such as ArrayList.

                          Rob

                          Comment

                          Working...
                          X