在部署文件中设定了jdbc引用名jdbc/sample,jndi名字为jdbc/sample

来源:互联网 发布:富士伺服选型软件 编辑:程序博客网 时间:2024/05/22 13:24
在部署文件中设定了jdbc引用名jdbc/sample,jndi名字为jdbc/sample
如果采用如下代码:
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/sample");
conn = ds.getConnection();

运行就报错:05-7-1 10:02:24:178 CST] 00000031 SystemErr R Naming-Exception: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.

去掉“java:comp/env/”就好了。

解决:确认部署后在概要表空间下的config/cells/CN7642012HNode01Cell/applications目录下相应应用的web.xml文件下有正确的配置JNDI,如:
<b><resource-ref id="ResourceRef_1097466019938"></b>
<res-ref-name>jdbc/yjjndi</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
再查看同目录下的ibm-web-bnd.xmi文件中id是否和上面的id相同,如下(注意粗体部分):
<b><resRefBindings xmi:id="ResourceRefBinding_1097466019938" jndiName="jdbc/yjjndi" loginConfigurationName="DefaultPrincipalMapping">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1097466019938"/></b>
<properties xmi:id="Property_1165956970219" name="com.ibm.mapping.authDataAlias" value="CN7642012HNode01/yjj2c" description="description"/>
</resRefBindings>  
原创粉丝点击