title: What is resource-ref in web.xml used for?
body: <p>I'm just wondering when/why you would define a <code>&lt;resource-ref&gt;</code> element in your <code>web.xml</code> file?</p>
  
  <p>I would have thought that it would be defined in your web/app server using JNDI and then look up the JNDI reference in your Java code?</p>
  
  <p>The resource-ref definition seems a bit redundant to me and I can't think of when it might be useful. Example:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;resource-ref&gt;
    &lt;description&gt;Primary database&lt;/description&gt;
    &lt;res-ref-name&gt;jdbc/primaryDB&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>