CWNEN0030E 在 Websphere Liberty 中查找数据源 JNDI 时出错

CWNEN0030E error on DataSource JNDI lookup in Websphere Liberty

我尝试将 WAS 传统 8.5 websphere 配置转换为 websphere liberty 20.x 配置,但出现错误。我相信连接设置正确,名称正确,驱动程序的 jar 文件存在但出现以下错误。

基本上就是配置了。

<dataSource jndiName="jdbc/db2a" type="javax.sql.DataSource">       
       <jdbcDriver javax.sql.DataSource="com.ibm.db2.jcc.DB2Driver" libraryRef="DB2JCCLib"/>
       <properties.db2.jcc  driverType="4" databaseName="DB1" serverName="host.name" portNumber="446"/>             
    </dataSource>


<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 name="jdbc/db2a" binding-name="jdbc/db2a"/>
</web-bnd>

...

server.xml

顶部的配置
<!-- Enable features -->
<featureManager>
    <feature>appSecurity-2.0</feature>
    <feature>jaxrs-2.0</feature>
    <feature>jsp-2.3</feature>
    <feature>localConnector-1.0</feature>
    <feature>jaxws-2.2</feature>
    <feature>ldapRegistry-3.0</feature>
</featureManager>

jar 文件是:db2jcc4-4.22.29.jar

并参考那个 jar/class 文件。

连接的java代码是标准的jdbc连接:

DriverManager.getConnection (connStr);

还有这个:

            InitialContext initialContext = new InitialContext();
            Context context = (Context)initialContext.lookup("java:comp/env");
            DataSource dataSource = (DataSource)context.lookup(string5);
            logger.info((Object)"CVDBBackendHandler.getConnection() out");
            return dataSource.getConnection();

错误如下。

根异常是 com.ibm.wsspi.injectionengine.InjectionException:CWNEN0030E:服务器无法获取 java:comp/env/jdbc/db2a 引用的对象实例。异常消息是:CWNEN1003E: 服务器无法为 java:comp/env/jdbc/db2a 引用找到具有 java.lang.Object 类型的 jdbc/db2a 绑定。

配置有误。 com.ibm.db2.jcc.DB2Driver 不是 javax.sql.DataSource.

的实现

您可以删除配置属性 javax.sql.DataSource="com.ibm.db2.jcc.DB2Driver" 并让 Liberty 中的内置知识从 JDBC 驱动程序 jar 中推断它,或者您可以将其指定为, javax.sql.DataSource="com.ibm.db2.jcc.DB2DataSource"

以上数据源class名称可以在DB2文档中找到here

您需要将 JDBC 功能之一添加到您的功能列表中,例如

<featureManager>
    <feature>jdbc-4.3</feature>
</featureManager>

(或较早的 JDBC 功能之一,例如 jdbc-4.2,等等)。

虽然您的 messages.log 应该显示这样的功能集(包括从您明确启用的功能中提取的功能):

CWWKF0012I: The server installed the following features: [appSecurity-2.0, distributedMap-1.0, el-3.0, federatedRegistry-1.0, jaxb-2.2, jaxrs-2.0, jaxrsClient-2.0, jaxws-2.2, jndi-1.0, json-1.0, jsp-2.3, ldapRegistry-3.0, localConnector-1.0, servlet-3.1, ssl-1.0].

此列表不包含任何激活 JDBC 功能的内容,因此您必须明确启用它。 (另一方面,请注意执行 JNDI 查找所需的 jndi-1.0 功能已包括在内,即使它不是您直接添加到 server.xml 的功能,因为其中一个其他功能包括在内)。

一些有用的参考链接: