1
votes

Im using WebSphere 8.5.5 Liberty profile to deploy an application that is using a datasource defined and exposed thru jndi. But im unable to use the datasource from my application. My server.xml looks like this:

<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>jndi-1.0</feature>
        <feature>ejbLite-3.1</feature>
        <feature>jdbc-4.0</feature>
    </featureManager>

    <dataSource id="mssqlserver" jndiName="jdbc/sqlserver_prod" type="javax.sql.DataSource">
        <jdbcDriver libraryRef="MSJDBCLib"/>
        <connectionManager numConnectionsPerThreadLocal="10" id="ConnectionManager" minPoolSize="1"/>
        <properties.microsoft.sqlserver username="sa" password="" databaseName="PROD"
                                    serverName="10.211.55.4" portNumber="1433"/>
    </dataSource>

    <library id="MSJDBCLib">
        <fileset dir="/Users/alter/Devel/sqlserver" includes="sqljdbc4.jar"/>
    </library>

    <httpEndpoint id="defaultHttpEndpoint"
                  host="0.0.0.0"
                  httpPort="9080"
                  httpsPort="9443" />
    <application id="ee1" location="/Users/alter/Devel/xxxx/src/ear/target/ee1-ear.ear" name="ear_ear_exploded" type="ear" >
        <classloader delegation="parentLast" commonLibraryRef="MSJDBCLib" />
    </application>

    <application id="ee1-web" location="/Users/alter/Devel/xxxx/src/web/target/ee1-web" name="web_exploded" type="war" />
</server>

Im using this spring configuration file to inject the datasource:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <!-- START CONFIG DS -->

    <bean id="dataSourcePROD" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc/sqlserver_prod"/>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSourcePROD"/>
        <property name="mapperLocations" value="classpath*:mappers/**/*.xml"/>
    </bean>

    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory"/>
    </bean>

    <bean id="genericMapper" class="org.mybatis.spring.mapper.MapperFactoryBean" abstract="true">
        <property name="sqlSessionTemplate" ref="sqlSessionTemplate"/>
        <property name="addToConfig" value="true"/>
    </bean>
</beans>

Spring is able to found my "datasource" object from JNDI, but it can't cast the delivered object to javax.sql.Datasource. The actual exception is :

org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.ibm.ws.jdbc.DataSourceService' to required type 'javax.sql.DataSource' for property 'dataSource';

Note1: I have no reference to the jdbc drivers in the deployable artifacts (ear, wars, etc...)

Im missing some configuration parameters in server.xml for the datasource definition??.

3
I don't see anything wrong with your configuration. That error looks like a product issue. I recommend opening a PMR with IBM.Brett Kail

3 Answers

0
votes

you may want to have a look at the Spring helper class WebSphereDataSourceAdapter. IBM has a knack of 'wrapping' services in services which requires a little 'unwrapping' to use.

have a look at this in the Spring API docs as a possible hint on what to try

0
votes

I have similar code working but I've added the spring jee:jndi-lookup tag for lookup of the datasource inside spring.

<jee:jndi-lookup id="dataSourcePROD" jndi-name="jdbc/sqlserver_prodS" resource-ref="false" expected-type="javax.sql.DataSource"/>
0
votes

username is wrong attribute in properties.microsoft.sqlserver element. You should use user instead:

<properties.microsoft.sqlserver user="sa" password="" databaseName="PROD"
                                serverName="10.211.55.4" portNumber="1433"/>