title: how to convert jndi lookup from xml to java config
body: <p>Currently I'm converting the xml to java config. But I stuck at some part that I have been research for several days. Here the problem:</p>
  
  <p>Xml config:</p>
  
  <pre><code>     &lt;jee:jndi-lookup id="dbDataSource" jndi-name="${db.jndi}" resource-ref="true" /&gt;
  
       &lt;beans:bean id="jdbcTemplate"
       class="org.springframework.jdbc.core.JdbcTemplate" &gt;
       &lt;beans:property name="dataSource" ref="dbDataSource"&gt;&lt;/beans:property&gt;
       &lt;/beans:bean&gt;
  </code></pre>
  
  <p>So far I managed to convert this code:</p>
  
  <p><code>&lt;jee:jndi-lookup id="dbDataSource" jndi-name="${db.jndi}" resource-ref="true" /&gt;</code></p>
  
  <p>to this :</p>
  
  <pre><code>@Bean(name = "dbDataSource")
  public JndiObjectFactoryBean dataSource() {
     JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
     bean.setJndiName("${db.jndi}");
     bean.setResourceRef(true); 
     return bean; 
  }
  </code></pre>
  
  <p>And this :</p>
  
  <pre><code>     &lt;beans:bean id="jdbcTemplate"
       class="org.springframework.jdbc.core.JdbcTemplate" &gt;
       &lt;beans:property name="dataSource" ref="dbDataSource"&gt;&lt;/beans:property&gt;
       &lt;/beans:bean&gt;
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>@Bean(name = "jdbcTemplate")
  public JdbcTemplate jdbcTemplate() { 
     JdbcTemplate jt = new JdbcTemplate();
      jt.setDataSource(dataSource);
      return jt;
     }
  </code></pre>
  
  <p>The problem is the method <strong>setDataSource()</strong> need DataSource object but I'm not sure how to relate both bean.How to pass the JndiObjectFactoryBean to DataSource?</p>
  
  <p>Or do I need to use another method?</p>
  
  <p>Extra Question: </p>
  
  <p>The <code>bean.setJndiName("${db.jndi}")</code> , <strong><em>${db.jndi}</em></strong> is refer to properties file but I always got NameNotFoundException, How to make it work?</p>
  
  <p>Thanks!!</p>