title: DataSource not injected to @Resource annotated field with alwaysUseJndiLookup setting
body: <p>I've just read about <code>@Resource</code> annotation from this article (<a href="http://www.infoq.com/articles/spring-2.5-part-1" rel="nofollow">http://www.infoq.com/articles/spring-2.5-part-1</a>) and wish to use it on Tomcat 6.0.26 and Spring 3.0.3</p>
  
  <p>But it does not work -- field <code>ds</code> in <code>Users</code> class does not initialized and I've got <code>NullPointerException</code> when I try to made a query.</p>
  
  <p>File <code>src/org/example/db/Users.java</code></p>
  
  <pre><code>package org.example.db;
  import javax.sql.DataSource;
  import javax.annotation.Resource;
  
  @Repository
  public class Users {
  
   @Resource private DataSource ds;
   ...
  }
  </code></pre>
  
  <p>File <code>WEB-INF/spring-servlet.xml</code></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/jee
   http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
   &lt;context:component-scan base-package="org.example.web.controller,org.example.db" /&gt;
  
   &lt;bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"&gt;
    &lt;property name="alwaysUseJndiLookup" value="true" /&gt;
   &lt;/bean&gt;
  
   &lt;jee:jndi-lookup id="ds" jndi-name="java:comp/env/jdbc/mydb" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>File <code>WEB-INF/web.xml</code></p>
  
  <pre><code> &lt;resource-ref&gt;
    &lt;description&gt;DB Connection&lt;/description&gt;
    &lt;res-ref-name&gt;jdbc/mydb&lt;/res-ref-name&gt;
    &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
    &lt;res-auth&gt;Container&lt;/res-auth&gt;
   &lt;/resource-ref&gt;
  </code></pre>
  
  <p>In log file:</p>
  
  <pre><code>DEBUG 2010-09-27 21:56:00,085: Creating shared instance of singleton bean 'ds'
  DEBUG 2010-09-27 21:56:00,085: Creating instance of bean 'ds'
  DEBUG 2010-09-27 21:56:00,086: Eagerly caching bean 'ds' to allow for resolving potential circular references
  DEBUG 2010-09-27 21:56:00,106: Invoking afterPropertiesSet() on bean with name 'ds'
  DEBUG 2010-09-27 21:56:00,116: Finished creating instance of bean 'ds'
  DEBUG 2010-09-27 21:56:00,149: Found injected element on class [org.example.db.Users]: ResourceElement for private javax.sql.DataSource org.example.db.Users.ds
  DEBUG 2010-09-27 21:56:00,152: Found injected element on class [org.example.db.Users]: ResourceElement for private javax.sql.DataSource org.example.db.Users.ds
  DEBUG 2010-09-27 21:56:00,161: Processing injected method of bean 'users': ResourceElement for private javax.sql.DataSource org.example.db.Users.ds
  DEBUG 2010-09-27 21:56:00,163: Returning cached instance of singleton bean 'ds'
  DEBUG 2010-09-27 21:56:00,442: Returning cached instance of singleton bean 'ds'
  DEBUG 2010-09-27 21:56:00,593: Rejected bean name 'ds': no URL paths identified
  DEBUG 2010-09-27 21:56:00,738: Rejected bean name 'ds': no URL paths identified
  </code></pre>
  
  <p>I don't know why it does not work. I found in <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.html" rel="nofollow">documentation</a> this:</p>
  
  <blockquote>
    <p>NOTE: A default CommonAnnotationBeanPostProcessor will be registered by the "context:annotation-config" and "context:component-scan" XML tags. Remove or turn off the default annotation configuration there if you intend to specify a custom CommonAnnotationBeanPostProcessor bean definition! </p>
  </blockquote>
  
  <p>I think it may be about my problem, but in this case I don't know how to "Remove or turn off the default annotation configuration".</p>
  
  <p>Please help.
  Thanks in advance!</p>