title: Spring-Core JNDI Configuration with beans
body: <p>Lets take I have a class as shown below :</p>
  
  <pre><code>public interface UserDAO {
      public List&lt;User&gt; list();
  }
  
  public class UserDAOImpl implements UserDAO {
      private DataSource dataSource;
  
      public UserDAOImpl(DataSource dataSource) {
          this.dataSource = dataSource;
   }
  </code></pre>
  
  <p>Let's assume JNDI configuration is done correctly in tomcat.</p>
  
  <p>Now for spring bean mapping in many sites I found the below configuration:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiName" value="java:comp/env/jdbc/UsersDB"/&gt;
  &lt;/bean&gt;
  
      &lt;bean id="userDao" class="net.codejava.spring.dao.UserDAOImpl"&gt;
      &lt;constructor-arg&gt;
          &lt;ref bean="dataSource" /&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Here is what my question , UserDAOImpl class is looking for DataSource object but we are injecting JndiObjectFactoryBean object[Which is not a subclass of DataSource] , since we are not even mentioning the factory method how or where the conversion is happening ?</p>