title: Working of Resource Injection @Resource and Spring Framework?
body: <p>I want to understand how the annotation works. I have this piece of code which I have used in a simple Spring project.</p>
  
  <pre><code>@Resource(name="dataSource")
  private DataSource dataSouce;
  </code></pre>
  
  <p>The dataSource I have defined in an XML config file:</p>
  
  <pre><code>&lt;!-- The Apache DBCP implementation of DataSource --&gt;
      &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="org.h2.Driver"/&gt;
          &lt;property name="url" value="jdbc:h2:tcp://localhost/~/test"/&gt;
          &lt;property name="username" value="sa"/&gt;
          &lt;property name="password" value=""/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Other snippet from spring xml config file</p>
  
  <pre><code>    &lt;context:annotation-config /&gt; &lt;!-- This enables the annotation's actions, else annotations don't do their work. --&gt;
      &lt;context:component-scan base-package="com.example.dao.jdbc.impl"/&gt; &lt;!-- This is for component scan --&gt;
      &lt;bean id="jdbcOperImpl" class="com.example.dao.jdbc.impl.JdbcOperImpl"/&gt;
  </code></pre>
  
  <p>As I understand the Resource annotations comes from <code>javax.annotation.Resource</code>. I looked its <a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/annotation/Resource.java" rel="nofollow">source code</a>, and I notices the annotation is defined by JDK SE, and it is just a simple definition of an annotation. How does this do the injection? Does Spring Framework use this annotation and does Injection? How is <code>@Resource</code> annotation and Spring framework related?</p>