title: How do I inject a value from Properties file to a field of an existing instance (not managed by Spring) using Spring annotations?
body: <p>Here's what I wrote:</p>
  
  <p>com.MyTest.java</p>
  
  <pre><code>package com;
  
  import org.junit.Before;
  import org.junit.Test;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class MyTest {
  
      @Value( "${env}" )
      public String env;
  
      @Value( "#{env}" )
      public String env2;
  
      @Before
      public void init() {
          ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext( 
              "myTest.xml"
           );
          appCtx.getBeanFactory().autowireBean( this );
          // appCtx.getAutowireCapableBeanFactory().autowireBean( this ); // doesn't make a difference
      }
  
      @Test
      public void test() {
          System.out.println( "env is :"+ this.env );
          System.out.println( "env is :"+ this.env2 );
      }
  
  }
  </code></pre>
  
  <p>myTest.properties</p>
  
  <pre><code>env=QA
  </code></pre>
  
  <p>myTest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:util="http://www.springframework.org/schema/util"
      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.0.xsd
      "&gt;
  
  
      &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;classpath:myTest.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt; 
          &lt;property name="ignoreUnresolvablePlaceholders" value="false"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>pom.xml (important parts only)</p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.11&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;4.1.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
              &lt;version&gt;4.1.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>env is :null
  env is :null
  </code></pre>
  
  <p>My expected output:</p>
  
  <pre><code>env is :QA
  env is :QA
  </code></pre>
  
  <p>How do I inject a value from Properties file to a field of an existing instance using Spring annotations?</p>