Search code examples
javadb2webspherewebsphere-liberty

CWNEN0030E error on DataSource JNDI lookup in Websphere Liberty


I am try to convert a WAS traditional 8.5 websphere configuration to a websphere liberty 20.x configuration and getting an error. I believe the connection settings are right, the names are correct, the jar file for the driver exists but getting the error below.

Here is essentially the configuration.

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

...

Configuration at top of 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>

The jar file is : db2jcc4-4.22.29.jar

And has as reference to that jar / class file.

The java code for the connection is standard jdbc connection:

DriverManager.getConnection (connStr);

And this:

            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();

The error is below.

Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/jdbc/db2a reference. The exception message was: CWNEN1003E: The server was unable to find the jdbc/db2a binding with the java.lang.Object type for the java:comp/env/jdbc/db2a reference.


Solution

  • You need to add one of the JDBC features to your feature list, e.g.

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

    (or one of the earlier JDBC features, e.g.jdbc-4.2, etc.).

    Though your messages.log should show a feature set like this (including features pulled in from the features you explicitly enabled):

    CWWKF0012I: The server installed the following features: [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].

    this list doesn't include any activating the JDBC feature, so you must explicitly enable it. (On the other hand, note the jndi-1.0 feature required to do JNDI lookups is included even though it wasn't one you added directly to server.xml, since one of the other features included it).

    Some helpful links for reference: