Announcement Announcement Module
Collapse
No announcement yet.
Setting a bean property or constructor arg from a property expression Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting a bean property or constructor arg from a property expression

    Hey guys ...
    I have some queries about "Setting a bean property or constructor arg from a property expression"
    Bellow code are from spring-doc-1.1.5 ( like http://static.springsource.org/sprin...s.html#d0e2047 )

    // target bean to be referenced by name
    Code:
    <bean id="person" class="org.springframework.beans.TestBean" 
    singleton="false">
      <property name="age"><value>10</value></property>
      <property name="spouse">
        <bean class="org.springframework.beans.TestBean">
          <property name="age"><value>11</value></property>
        </bean>
      </property>
    </bean>
    // will result in 11, which is the value of property 'spouse.age' of bean 'person'
    Code:
    <bean id="theAge" class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
      <property name="targetBeanName"><value>person</value></property>
      <property name="propertyPath"><value>spouse.age</value></property>
    </bean>
    I understand all the above configuration but I don't know how to use the "theAge" bean reference of the second bean definition.
    How to inject the bean "theAge" to some other bean ?

    suppose
    Code:
    package somepackage;
    public class someclass{
          private int age;
          // getter and setter//
          public String toString(){
                 return "someclas { age:"+this.age+" }";
          }
    }
    will it be like this
    Code:
          <bean  id="someclass1"     class="somepackage.someclass">
                <property   name="age">
                     <value>theAge</value> or <ref>theAge</ref>
                </property>
          </bean
    Please some one tell me ....
    Thank you...
Working...
X