Announcement Announcement Module
Collapse
No announcement yet.
Eclipse and Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Eclipse and Spring

    Hi,
    I am a very newbie to both Eclipse and Spring. I have installed Eclipse 3.2.2 and the SpringIDE for eclipse. I think the set up is fine (I see Spring showing up in Project Properties, I see a small 's' on top of some of my files in eclipse - these are the files which are referred to in my config.xml (bean configuration files for spring?)

    Question: I am doing a very simple test case - An object that has another object (hence the dependency). I created the config.xml and referred to it in the Project Properties for Spring. My question is do we have to do any other specific thing for spring/eclipse to use this xml file? My xml file is very basic - I have an object customer that has two other objects (address and email.) my xml file is:

    <beans>
    <bean id="customer" class="Customer" depends-on="email, address" />

    <bean id="email" class="Email">
    <property name="fromEmail">
    <value>[email protected]</value>
    </property>
    <property name="userId">
    <value>user1</value>
    </property>
    <property name="password">
    <value>user1PWD</value>
    </property>
    <ref local="customer" />
    </bean>

    <bean id="address" class="Address">
    <property name="address1">
    <value>xyz drive</value>
    </property>
    <property name="address2">
    <value>null</value>
    </property>
    <property name="city">
    <value>Arlington</value>
    </property>
    <property name="state">
    <value>VA</value>
    </property>
    <property name="zipCode">
    <value>91223</value>
    </property>
    <ref local="customer" />
    </bean>

    </beans>


    I was under the understanding that the email and address properties would get set when the application was first started and hence customer would be able to automatically get those values but when I debug the test application (an instance of customer,) neither email nor address is set!

    Any ideas what I'm doing wrong or not understanding? Do we have to tell eclipse that it must use the config.xml?

    Thanks!
    Dipita

  • #2
    First, are your configuration files referenced by the contextConfiguration in web.xml?

    Second, "depends-on" does not inject the values of email or address into Customer. Customer must have an Email field and an Address field, and the customer bean must property elements nested inside it referencing the email and address bean to set the values.

    For example, if customer has a field named "emailField", the the customer bean must have:
    <property name="emailField" ref="email" />

    I could be wrong, but I don't think you need <ref local="customer" /> in the email or address beans. I don't think that is how that element is used.

    See section 3.3 here:
    http://static.springframework.org/sp...-instantiation

    Comment

    Working...
    X