WebSphere NameNotFoundException 在对名称 java 进行间接查找时发生:comp/env/jdbc/bar
WebSphere NameNotFoundException occurred on an indirect lookup on the name java: comp/env/jdbc/bar
我正在 websphere 8.5 上部署 java war
,但我在创建和使用 JDBC 数据源时遇到了一些问题。
这是ibm-web-bnd.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd" version="1.0">
<virtual-host name="default_host"/>
<resource-ref binding-name="jdbc/foobar" name="jdbc/bar"/>
</web-bnd>
这是 websphere 上的错误日志:
[5/19/17 11:17:21:137 UTC] 00000095 SystemOut O [TEMPLATE-MYCOMPANY-WP]2017-05-19 11:17:21,137 ERROR [WebContainer : 6] taaccess.provider.JNDIConnectionProvider:
Cannot get connection: com.ibm.websphere.naming.CannotInstantiateObjectException:
A NameNotFoundException occurred on an indirect lookup on the name java:comp/env/jdbc/bar.
The name java:comp/env/jdbc/bar maps to a JNDI name in deployment descriptor bindings for the application performing the JNDI lookup.
Make sure that the JNDI name mapping in the deployment descriptor binding is correct.
If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context.
[Root exception is javax.naming.NameNotFoundException: Context: DefaultCell01/nodes/DefaultNode01/servers/server1, name: jdbc/foobar: First component in name foobar not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]]
我的 websphere 数据源配置如下(测试连接正常)
- 姓名:
foo_bar
- JNDI 名称:
jdbc_foobarlocal
- 范围:
Node=DefaultNode01,Server=server1
- 提供商:
Oracle JDBC Driver
ibm-web-bnd.xml
是否在部署期间被忽略或我必须修改我的数据源?
ibm-web-bnd.xml
提供您在代码中使用的引用之间的映射 - 我假设它是 java:comp/env/jdbc/bar
- 以及在服务器配置中为该资源配置的实际 JNDI 名称 - 在您的情况下目前是jdbc_foobarlocal
。所以你有两个选择,要么保持 JNDI 名称不变,然后修改 xml 设置 binding-name=jdbc_foobarlocal
,要么将数据源上的 JNDI 名称更改为 jdbc/foobar
.
我正在 websphere 8.5 上部署 java war
,但我在创建和使用 JDBC 数据源时遇到了一些问题。
这是ibm-web-bnd.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd" version="1.0">
<virtual-host name="default_host"/>
<resource-ref binding-name="jdbc/foobar" name="jdbc/bar"/>
</web-bnd>
这是 websphere 上的错误日志:
[5/19/17 11:17:21:137 UTC] 00000095 SystemOut O [TEMPLATE-MYCOMPANY-WP]2017-05-19 11:17:21,137 ERROR [WebContainer : 6] taaccess.provider.JNDIConnectionProvider:
Cannot get connection: com.ibm.websphere.naming.CannotInstantiateObjectException:
A NameNotFoundException occurred on an indirect lookup on the name java:comp/env/jdbc/bar.
The name java:comp/env/jdbc/bar maps to a JNDI name in deployment descriptor bindings for the application performing the JNDI lookup.
Make sure that the JNDI name mapping in the deployment descriptor binding is correct.
If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context.
[Root exception is javax.naming.NameNotFoundException: Context: DefaultCell01/nodes/DefaultNode01/servers/server1, name: jdbc/foobar: First component in name foobar not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]]
我的 websphere 数据源配置如下(测试连接正常)
- 姓名:
foo_bar
- JNDI 名称:
jdbc_foobarlocal
- 范围:
Node=DefaultNode01,Server=server1
- 提供商:
Oracle JDBC Driver
ibm-web-bnd.xml
是否在部署期间被忽略或我必须修改我的数据源?
ibm-web-bnd.xml
提供您在代码中使用的引用之间的映射 - 我假设它是 java:comp/env/jdbc/bar
- 以及在服务器配置中为该资源配置的实际 JNDI 名称 - 在您的情况下目前是jdbc_foobarlocal
。所以你有两个选择,要么保持 JNDI 名称不变,然后修改 xml 设置 binding-name=jdbc_foobarlocal
,要么将数据源上的 JNDI 名称更改为 jdbc/foobar
.