title: Spring jUnit Testing properties file
body: <p>I have a jUnit Test that has its own properties file(application-test.properties) and its spring config file(application-core-test.xml). </p>
  
  <p>One of the method uses an object instantiated by spring config and that is a spring component. One of the members in the classes derives its value from application.properties which is our main properties file. While accessing this value through jUnit it is always null. I even tried changing the properties file to point to the actual properties file, but that doesnt seem to work. </p>
  
  <p>Here is how I am accessing the properties file object</p>
  
  <pre><code>@Component
  @PropertySource("classpath:application.properties")
  public abstract class A {
  
      @Value("${test.value}")
      public String value;
  
      public A(){
          SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
      }
  
      public A(String text) {
          this();
          // do something with text and value.. here is where I run into NPE
      }
  
  }
  
  public class B extends A { 
       //addtnl code
  
      private B() {
  
      }
  
  
      private B(String text) {
           super(text)
      }
  }
  
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations={"classpath:META-INF/spring/application-core-test.xml",
                               "classpath:META-INF/spring/application-schedule-test.xml"})
  @PropertySource("classpath:application-test.properties")
  public class TestD {
  
      @Value("${value.works}")
      public String valueWorks;
  
      @Test
      public void testBlah() {     
          SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
          B b= new B("blah");
          //...addtnl code
  
      }    
  }      
  </code></pre>