jdbc - 使用 WebSphere Liberty Profile 8.5 设置数据源

标签 jdbc jndi websphere-liberty

我的 Web 应用程序从 JNDI 获取数据源:

javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) 
    ctx.lookup("java:comp/env/jdbc/db");

在应用程序的 WEB-INF/web.xml , 我有:
<resource-ref>
    <description>DataSource</description>
    <res-ref-name>jdbc/db</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

在应用程序的 WEB-INF/ibm-web-bnd.xml , 我有:
<web-bnd
    xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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/db" binding-name="jdbc/db"/>
</web-bnd>

在 WebSphere Liberty Profile 的 server.xml 中,我有(保留相关部分):
<server description="new server">

    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>jdbc-4.0</feature>
    </featureManager>

    <library id="oracle-lib">
        <fileset dir="lib" includes="ojdbc5_g.jar"/>
    </library>

    <dataSource jndiName="jdbc/db" jdbcDriverRef="oracle-driver" type="javax.sql.DataSource">
        <jdbcDriver libraryRef="oracle-lib" id="oracle-driver"/>
        <connectionManager numConnectionsPerThreadLocal="10" id="ConnectionManager" minPoolSize="1"/>
        <properties user="user" password="password"
                    url="jdbc:oracle:thin:@//db-server:1521/db"/>
    </dataSource>

</server>

当应用程序尝试从 JNDI 获取数据源时,它会失败并出现以下错误:
CWNEN0030E: The @Resource factory encountered a problem getting
the object instance jdbc/oracle binding object.  The exception message was: 
failed to resolve jdbc/oracle to javax.sql.DataSource: 
javax.naming.NameNotFoundException: 
Intermediate context does not exist: jdbc/oracle

我在这里缺少什么?

最佳答案

我们在 Liberty 8.5.5 上使用 DB2,并且在 server.xml 中有

<dataSource id="db2" isolationLevel="TRANSACTION_READ_COMMITTED" jndiName="jdbc/db2" type="javax.sql.DataSource">
    <jdbcDriver>
        <library>
            <fileset dir="/usr/lib/java/ibm-db2-universal-driver" includes="db2jcc4.jar, db2jcc_license_cisuz.jar, db2jcc_license_cu.jar"/>
        </library>
    </jdbcDriver>

    <properties.db2.jcc databaseName="DB2T" portNumber="21020" serverName="db2t.lvm.de"/>
    <containerAuthData password="{xor}KzspMC04" user="tdvorg"/>
</dataSource>

也许有帮助。

罗伯特

关于jdbc - 使用 WebSphere Liberty Profile 8.5 设置数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17822106/

相关文章:

Hibernate 5.0 方言自动检测不适用于 Tomcat 上的 JNDI

jakarta-ee - 如何访问weblogic 10.3.6中定义的JNDI数据源

intellij-idea - IntelliJ IDEA 部署后 Wildfly 无法加载部署

java - 是否可以在 WebSphere Liberty 中查询/浏览 JNDI 树?

java - 使用 JDBC 连接 Android/MySQL

java - 数据库更新后出现 ORA-01733(此处不允许使用虚拟列)

ssl - 如何确定要使用的密码(解决 logjam 漏洞)

java - 使用 JAX-RS 时,有没有办法将变量放入自定义 ConstraintValidator 中?

java - 使用 Projections.rowCount() 的 Hibernate 标准查询会导致数字溢出

java - 将 DATETIME 从 SQLite 解析为 java.SQL.Timestamp 时出错