0
votes

Here Am trying to migrating application from WAS 8 to Liberty. While running the application am getting error about JNDI lookup,

ERROR

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 FILE

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

1 Answers

1
votes

In order for the binding file to associate a resource reference in web.xml with an server resource in server.xml, the res-ref-name in web.xml needs to match the name in IBM-WEB-BND.XML, ie, change <resource-ref name="HRONLINEFSDEV2" to <resource-ref name="HRONLINEFSQA2" (or vice versa). Also, your java code needs to lookup the jndi name specified in the binding file by binding-name="jdbc/hronline/ds_FSDEV2" like this

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