NameNotFoundException: While trying to lookup 'jdbc' only when publishing from Eclipse Kepler but not Indigo

我怕爱的太早我们不能终老 提交于 2019-12-01 05:13:06

After a week or so of trial and error / process of elimination I've managed to resolve this issue and get a better understanding of the necessary mappings. As Elliott suspected this was a problem with the JNDI lookup. It was compounded by the fact that it (inadvertently) works as expected when published from Indigo to weblogic 12.1.1 (I'm still unsure why that's the case).

My initial attempts to resolve this had focused on the mappings in the weblogic.xml. As I was publishing to a weblogic server I was in incorrectly assuming this was referenced when resolving the data source. As it turns out this isn't the case and my configuration didn't require a weblogic.xml resource-description.

The applicationContext.xml remains the same...

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
 <property name="jndiName" value="java:comp/env/jdbc/oraclexe" />
</bean>

However, the jndiName value of java:comp/env/jdbc/oraclexe maps to the web.xml res-ref-name value jdbc/oraclexe (and not the weblogic.xml res-ref-name as I'd wrongly assumed)...

The web.xml mapped-name has been amended...

<resource-ref>
 <description>Oracle Weblogic console JDBC Data Source</description>
 <res-ref-name>jdbc/oraclexe</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
 <mapped-name>oraclexe</mapped-name>
</resource-ref>

...it's then the mapped-name value oraclexe that maps to the Weblogic console JDBC Data Source JNDI name.

The resource-description node in the weblogic.xml has now been completely omitted as its not referenced in this particular configuration.

In my case, configuration was Weblogic 12.1.3 and Eclipse Mars 4.5.0; the ear worked fine deployed on wls but I had the same error when publishing from elipse. The problem was that the destiny of the datasource was a server created to deploy the application, and the eclipse published it on AdminServer. I added both destinies to the datasource, and it worked ok.

This is a configuration that worked for me:

applicationContext.xml

<jee:jndi-lookup id="dataSource" resource-ref="true"
    jndi-name="jdbc/alias" expected-type="javax.sql.DataSource" />

web.xml

<resource-ref>
   <res-ref-name>jdbc/alias</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

weblogic.xml

<wls:resource-description>
    <wls:res-ref-name>jdbc/alias</wls:res-ref-name>
    <wls:jndi-name>jdbc/resource/weblogic</wls:jndi-name>
</wls:resource-description>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!