如何使用Websphere Liberty Profile 8.5中定义的数据源?

问题描述 投票:1回答:3

我使用WebSphere 8.5.5 Liberty配置文件来部署使用通过jndi定义和公开的数据源的应用程序。但我无法使用我的应用程序中的数据源。我的server.xml看起来像这样:

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

我使用这个spring配置文件来注入数据源:

<?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能够从JNDI找到我的“datasource”对象,但它无法将传递的对象强制转换为javax.sql.Datasource。实际的例外是:

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

注1:我没有参考可部署工件中的jdbc驱动程序(耳朵,战争等......)

我在server.xml中缺少一些数据源定义的配置参数??

java spring datasource jndi websphere-liberty
3个回答
0
投票

你可能想看看Spring助手类WebSphereDataSourceAdapter。 IBM在服务中具有“包装”服务的诀窍,需要稍微“解包”才能使用。

在Spring API文档中查看this作为可能提示尝试的提示


0
投票

我有类似的代码工作,但我添加了spring jee:jndi-lookup标签,用于在spring中查找数据源。

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

0
投票

username是属性.microsoft.sqlserver元素中的用户名是错误的属性。您应该使用用户:

<properties.microsoft.sqlserver user="sa" password="" databaseName="PROD"
                                serverName="10.211.55.4" portNumber="1433"/>
© www.soinside.com 2019 - 2024. All rights reserved.