title: AutowireCapableBeanFactory: How to initialize primitive properties
body: <p>I have some programmatically created beans that I am initializing via <code>AutowireCapableBeanFactory.autowireBean()</code> as shown below:</p>
  
  <p>spring.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
      &lt;context:annotation-config/&gt;
  
      &lt;bean id="MyService" class="..."&gt;
          &lt;property name="someProp" value="primitiveValue"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="MyBean" class="..."&gt;
          &lt;property name="someString" value="primitiveValue"/&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>MyBean.java</p>
  
  <pre><code>public class MyBean implements InitializingBean {
  
      @Autowired MyService myService;
  
      private String someString;
      public void setSomeString (String someString) {
          this.someString = someString;
      }
      public void afterPropertiesSet () {}
  }
  </code></pre>
  
  <p>Caller:</p>
  
  <pre><code>MyBean bean = new MyBean(arg1, arg2, arg3);
  autowireCapableBeanFactory.autowireBean(bean);
  </code></pre>
  
  <p>This correctly autowires <code>bean.myService</code> as expected. However it does not populate primitive properties like <code>bean.someString</code>.</p>
  
  <p>Looking at the docs and <a href="https://stackoverflow.com/a/11965771/1800023">this answer</a>, I though something like this would work:</p>
  
  <pre><code>MyBean bean = new MyBean(arg1, arg2, arg3);
  autowireCapableBeanFactory.autowireBean(bean);
  autowireCapableBeanFactory.initializeBean(bean, "name");
  </code></pre>
  
  <p>But alas, <code>someString</code> is still <code>null</code>. I have found lots of references stating what <em>will not</em> work to initialize class properties, but nothing showing what <em>will</em> work.</p>
  
  <p>Any ideas?</p>