title: How do I inject property from one bean into another in Spring 3.0?
body: <p>In Spring 3.0.2, I am trying to inject the property of Bean A into another Bean B, but the Spring EL isn't working.</p>
  
  <p>Bean A is being created manually in Java. Bean B is created through XML.</p>
  
  <p>In this case <strong>Bean A is Potato</strong> and <strong>Bean B is Baby</strong> (both in package springinit).</p>
  
  <p>Bean A (Potato):</p>
  
  <pre><code>public class Potato {
     String potatoType;
  
     public String getPotatoType() { return potatoType; }
  
     public void setPotatoType(String potatoType) { this.potatoType = potatoType; }
  
     @Override
     public String toString() {
         return "Potato{" + "potatoType=" + potatoType + '}';
     }
  }
  </code></pre>
  
  <p>Bean B (Baby):</p>
  
  <pre><code>public class Baby {
  
      private String name;
      private Potato potatoThing;
  
      public String getName() { return name; }
  
      public void setName(String name) { this.name = name; }
  
      public Potato getPotatoThing() { return potatoThing; }
  
      public void setPotatoThing(Potato p) { this.potatoThing = p; }
  
      @Override
      public String toString() {
          return "Baby{" + "name=" + name +
                  ", potatoThing=" + potatoThing + '}';
      }
  }
  </code></pre>
  
  <p>In my Main class, I create a Potato and use it in the XML when trying to make a Baby</p>
  
  <pre><code>package springinit;
  
  import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
  import org.springframework.context.support.GenericApplicationContext;
  import org.springframework.core.io.ClassPathResource;
  
  public class Main {
  
      public static void main(String[] args) {
          GenericApplicationContext ctx= new GenericApplicationContext();
  
          // define java-based spring bean
          ctx.registerBeanDefinition("myPotato", 
                  genericBeanDefinition(Potato.class)
                      .addPropertyValue("potatoType", "spudzz")
                      .getBeanDefinition());
  
          // read in XML-bean
          XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
          xmlReader.loadBeanDefinitions(
                  new ClassPathResource("/resources/spring_init.xml"));
  
          // print out results
          System.out.format(
                  "Baby: %s%n%n" +
                  "Potato: %s%n",
                  ctx.getBean(Baby.class),
                  ctx.getBean(Potato.class)
          );
      }
  }
  </code></pre>
  
  <p>Here's my spring_init.xml:
      </p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
    &lt;bean id="myBaby" class="springinit.Baby" depends-on="myPotato"&gt;
        &lt;property name="name" value="#{myPotato.potatoType}" /&gt;
        &lt;property name="potatoThing"&gt;
            &lt;ref bean="myPotato" /&gt;
            &lt;/property&gt;
    &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>When I run main, I get this output:</p>
  
  <pre><code>Baby: Baby{name=#{myPotato.potatoType}, potatoThing=Potato{potatoType=spudzz}}
  
  Potato: Potato{potatoType=spudzz}
  </code></pre>
  
  <p>I want the baby's name to be "spudzz", which is a property of myPotato. Why won't spring inject this value into the baby?</p>
  
  <p>Thank you for reading. I hope it was clear enough.</p>