title: Spring: Adding autowired property to list
body: <p>I have a bean defined in xml configuration as:</p>
  
  <pre><code>&lt;bean id="dataService" class="com.sample.DataService" /&gt;
  </code></pre>
  
  <p>In another class it is used as resource and put in a list.</p>
  
  <pre><code>@Resource(name = "dataService")
  private Driver dataService;
  
  private List&lt;Driver&gt; drivers = new ArrayList&lt;Driver&gt;() {
          {
              drivers.add(dataService);
          }
  };
  </code></pre>
  
  <p>I am getting <code>NullPointer Exception</code> on line <code>drivers.add(dataService);</code> I thought dataService should not be null as it is autowired. What am I missing here? </p>