title: using @Autowired with static variable
body: <p>I try to run the following and get NullPointerException in main function. I don't know why this @Autowired method doesn't initialize surveyDao variable.
  Below is related code:</p>
  
  <pre><code>@ContextConfiguration( locations = {"test-context.xml"} )
  @TransactionConfiguration(defaultRollback=true)
  
  @Transactional
  public class MyTest {    
  
  
  protected static SurveyDao surveyDao;
  
  
  @Autowired
  public void setSurveyDao(SurveyDao surveyDAO){
      MyTest.surveyDao = surveyDAO;
  }
  
  
  public static void main(String args[]) {
      CollectSurvey survey = surveyDao.load("form");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Content of test-context.xml is as follows:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:security="http://www.springframework.org/schema/security"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xmlns:p="http://www.springframework.org/schema/p"
      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.1.xsd
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
      default-lazy-init="true"
      default-autowire="byName"&gt;
  
      &lt;context:annotation-config/&gt;
  
  
  &lt;!--     &lt;bean id="applicationContextProvider" class="org.openforis.collect.context.ApplicationContextAwareImpl" /&gt; --&gt;
  
      &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="location" value="file:${user.dir}/dev.properties"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
          &lt;property name="url" value="${collect.devdb.url}"/&gt;
          &lt;property name="username" value="${collect.devdb.username}" /&gt;
          &lt;property name="password" value="${collect.devdb.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="surveyDao" class="org.openforis.collect.persistence.SurveyDao" init-method="init"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dynamicTableDao" class="org.openforis.collect.persistence.DynamicTableDao"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt;
  &lt;/beans&gt;
  </code></pre>