【问题标题】:CWNEN0030E error on DataSource JNDI lookup in Websphere LibertyCWNEN0030E 在 Websphere Liberty 中查找数据源 JNDI 时出错
【发布时间】:2021-11-08 20:27:14
【问题描述】:

我正在尝试将 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 / 类文件的引用。

连接的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.lang.Object 类型的 jdbc/db2a 绑定,用于 java:comp/env/jdbc/db2a 引用。

【问题讨论】:

  • 你启用了哪些功能?
  • 我在上面贴过,见 featureManager 部分
  • 您缺少jdbc-4.x 功能
  • 是的,请看下面我的回答。

标签: java db2 websphere websphere-liberty


【解决方案1】:

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

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

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

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

CWWKF0012I:服务器安装了以下功能:[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 的功能,因为其他功能之一包含它) .

一些有用的参考链接:

【讨论】:

    【解决方案2】:

    配置中有错误。 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"

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

    【讨论】:

    • 是的,这是复制过去的错误,但仍然出现同样的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 2019-05-15
    • 2021-05-10
    • 2017-12-14
    相关资源
    最近更新 更多