java:comp/env/HRONLINEFSDEV2 JNDI 名称引用的对象无法在 Liberty 中实例化

The object referenced by the java:comp/env/HRONLINEFSDEV2 JNDI name could not be instantiated in Liberty

我正在尝试将应用程序从 WAS 8 迁移到 Liberty。 运行 应用程序收到关于 JNDI 查找的错误,

错误

CWNEN1001E: The object referenced by the java:comp/env/HRONLINEFSDEV2 JNDI name could not be instantiated. If the reference name maps to a JNDI name in the 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 com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/HRONLINEFSDEV2 reference. The exception message was: CWNEN1004E: The server was unable to find the HRONLINEFSDEV2 default binding with the javax.sql.DataSource type for the java:comp/env/HRONLINEFSDEV2 reference.]

WEB.XML

<resource-ref>
    <description>
    </description>
    <res-ref-name>HRONLINEFSDEV2</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

IBM-WEB-BND.XML

<resource-ref name="HRONLINEFSDEV2" binding-name="jdbc/hronline/ds_FSDEV2"/>

SERVER.XML

<dataSource id="HRONLINEFSDEV2" jndiName="jdbc/hronline/ds_FSDEV2" type="javax.sql.DataSource" jdbcDriverRef="Oracle_12.1.0.2">
        <properties.oracle databaseName="SF304D03" serverName="ECCDB1382.ECC1Q.FORD.COM" portNumber="1521" URL="jdbc:oracle:thin:@ECCDB1382.ECC1Q.FORD.COM:1521:SF304D03" statementCacheSize="50" name="HRONLINEFSDEV2" description="Data source template"/>
        <connectionManager agedTimeout="1200" connectionTimeout="180" maxIdleTime="1800" maxPoolSize="100" minPoolSize="1" reapTime="300"/>
    </dataSource>

JAVA 文件

initContext = new InitialContext();
ds = (DataSource) initContext.lookup("java:comp/env/jdbc/hronline/ds_FSDEV2");

为了使绑定文件将 web.xml 中的资源引用与 server.xml 中的服务器资源相关联,web.xml 中的 res-ref-name 需要匹配 name in IBM-WEB-BND.XML,即将<resource-ref name="HRONLINEFSDEV2"改为<resource-ref name="HRONLINEFSQA2"(反之亦然)。此外,您的 java 代码需要像这样

查找绑定文件中由 binding-name="jdbc/hronline/ds_FSDEV2" 指定的 jndi 名称

ds = (数据源) initContext.lookup("java:comp/env/jdbc/hronline/ds_FSDEV2);