title: Spring context does not initialize with @ContextConfiguration but does initialize with new ClassPathXmlApplicationContext
body: <p>I'm new to Spring and here's what I'm trying to do:</p>
  
  <p>I'm using a maven based library which has its own Spring context and autowired fields.<br/>
  Its beans config file is <code>src/test/resources/cucumber.xml</code><br/>
  I have a class like this in the library:</p>
  
  <pre><code>@Component
  public class ConfigContainer {
     @Value("${lc.service.uri}")
     private String lcServiceUri;
     @Value("${lc.service.port}")
     private Integer lcServicePort;   
     }
  }
  </code></pre>
  
  <p>Then I have a test application (based on maven and cucumber) where I want to use autowired fields from the library.<br/>
  The beans config file of my application is <code>src/test/resources/cucumber.xml</code><br/>
  I'm using <code>@RunWith(Cucumber.class)</code> to run the cucumber test.<br/>
  I have the following maven dependencies:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;3.8.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;info.cukes&lt;/groupId&gt;
          &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
          &lt;version&gt;1.2.4&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;info.cukes&lt;/groupId&gt;
          &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
          &lt;version&gt;1.2.4&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;info.cukes&lt;/groupId&gt;
          &lt;artifactId&gt;cucumber-spring&lt;/artifactId&gt;
          &lt;version&gt;1.2.4&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;theInternalLibrary&lt;/groupId&gt;
          &lt;artifactId&gt;internal-api-tests&lt;/artifactId&gt;
          &lt;version&gt;1.0.15-SNAPSHOT&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                  &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;info.cukes&lt;/groupId&gt;
                  &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;info.cukes&lt;/groupId&gt;
                  &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;info.cukes&lt;/groupId&gt;
                  &lt;artifactId&gt;cucumber-spring&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
          &lt;version&gt;4.1.6.RELEASE&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>When I try to inject this <code>ConfigContainer</code> into my application using the <code>@ContextConfiguration</code> and <code>@Autowired</code> annotations, the object value is <code>null</code>.</strong></p>
  
  <pre><code>@ContextConfiguration(locations = {"classpath:cucumber.xml"})
  public class CleanupTest {
     @Autowired
     protected ConfigContainer configContainer;
  }
  </code></pre>
  
  <p><strong>But if I inject it using <code>new ClassPathXmlApplicationContext("cucumber.xml")</code>, then the object is correctly initialized with the expected values.</strong></p>
  
  <pre><code>public class CleanupTest {
     protected ApplicationContext context = new ClassPathXmlApplicationContext("cucumber.xml");
     private ConfigContainer configContainer = (ConfigContainer)context.getBean("configContainer");
  }
  </code></pre>
  
  <p>Could you please explain to me why this is happening and what to do to be able to inject the field using spring annotations?<br/>
  Thanks.</p>