Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up a datasource with WebSphere Liberty Profile 8.5

My web app is getting a data source from JNDI with:

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

In the app's WEB-INF/web.xml, I have:

<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>

In the app's WEB-INF/ibm-web-bnd.xml, I have:

<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>

In WebSphere Liberty Profile's server.xml, I have (keeping on the relevant parts):

<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>

When the app attempts to get the datasource from JNDI, it fails with the following error:

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

What I am missing here?

like image 330
avernet Avatar asked Jul 23 '13 22:07

avernet


People also ask

What is data source in WebSphere Application Server?

4.2. Configuring JDBC data sources in IBM WebSphere Application Server. A data source is an object that enables a Java Database Connectivity (JDBC) client, such as an application server, to establish a connection with a database.

What is XA datasource in WebSphere?

XADataSource - a data source that supports application participation in any single-phase or two-phase transaction environment. When this data source is involved in a global transaction, the product transaction manager provides transaction recovery.


1 Answers

we use DB2 on Liberty 8.5.5 and we have in 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>

Maybe helps that.

Robert

like image 157
Robert Avatar answered Oct 06 '22 10:10

Robert