spring—java数据源能否转换为另一种数据源类型,如hikaridatasource?

q9yhzks0  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(245)

我遇到的情况是,我无法控制接收的数据源类型,无法更新发送给我的数据源。我从1.4版接收到一个apache commons basicdatasource。有没有办法在收到basicdatasource后将其转换为新版本的basicdatasource,或者甚至转换为hikaridatasource?
以下是一个代码场景供参考:

@Bean("dataSource")
public DataSource dataSource() throws Exception {
    try {
        return new JndiDataSourceLookup().getDataSource("jdbc/my_ds_name");
    } catch (Exception e) {
        log.error("Could not lookup data source!");
    }
}

另外,我也尝试了转换到另一个数据源类型,但是在转换过程中用户名和密码似乎丢失了。我得到jndidatasourcelookup在这里提供的任何东西。这是一个问题的原因是basicdatasource(v1.4)与mybatis的最新版本(3.5.x>=)不兼容。我现在得到以下错误:

java.lang.AbstractMethodError: Method org/apache/commons/dbcp/DelegatingResultSet.getObject(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; is abstract
    at org.apache.commons.dbcp.DelegatingResultSet.getObject(DelegatingResultSet.java) ~[?:?]
    at org.apache.ibatis.type.LocalDateTypeHandler.getNullableResult(LocalDateTypeHandler.java:38) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.type.LocalDateTypeHandler.getNullableResult(LocalDateTypeHandler.java:28) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createRowKeyForMappedProperties(DefaultResultSetHandler.java:1057) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createRowKey(DefaultResultSetHandler.java:1019) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:946) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:434) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:909) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:326) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:301) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:194) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.6.jar:3.5.6]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_162]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_162]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_162]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_162]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at com.sun.proxy.$Proxy75.selectList(Unknown Source) ~[?:?]
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) ~[mybatis-3.5.6.jar:3.5.6]

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题