Weblogic jndi NameNotFoundException occur with java config
<p>I been searching again for this issue where I cannot locate the jndi database by using java config. Before this I use xml and its work perfectly but in java config it cause an issue;</p>

<p>Xml code:</p>

<pre><code>     &lt;!-- Jndi database connection --&gt;
     &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>Java config now:</p>

<pre><code>@Bean(name = "dbDataSource")
public DataSource dataSource(@Value("${db.jndi}") String jndiName) 
{
    JndiDataSourceLookup lookup = new JndiDataSourceLookup();
    return lookup.getDataSource(jndiName);
}

@Bean
public JdbcTemplate jdbcTemplate(DataSource ds) { 
    return new JdbcTemplate(ds);
}
</code></pre>

<p>Properties file:</p>

<pre><code>db.jndi=jndi/myData
</code></pre>

<p>JNDI name in weblogic:</p>

<pre><code>jndi/myData
</code></pre>

<p>After change to java config, sometimes the system can read the database but rarely occur, until I clean and restart my computer then it can find the database, but usually its always trigger:</p>

<p><code>javax.naming.NameNotFoundException: Unable to resolve 'jndi.myData'. Resolved 'jndi'; remaining name 'myData'</code></p>

<p>Why the application cannot find the database correctly? 
Thanks!!!</p>