【发布时间】:2018-10-22 01:10:42
【问题描述】:
我刚刚升级了 Spring/SpringBoot 依赖项,并注意到 JdbcTemplate 类不再具有属性“nativeJdbcExtractor”。
我能够找到详细信息和背景: https://jira.spring.io/browse/SPR-14670
但是我找不到替换配置。我使用 commons-dbcp 库和 Spring 类,如 SimpleJdbcCall 等。我从不处理低级 JDBC API,但是如果供应商代码需要其真正的连接类型 (Oracle),则 nativeJdbcExtractor 设置确保它将在 Spring JDBC 代码(不是我的应用程序代码)中深入某个地方。如果我需要 Spring API 像过去那样自动处理这个问题,我不确定如何通过调用 connection.unwrap() 来解决这个问题。
java.lang.ClassCastException:org.apache.commons.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper 无法转换为 oracle.jdbc.OracleConnection
这是否隐藏在 DataSource 配置中的某个地方?我已经从 commons-dbcp 1.4 升级到 commons-dbcp2 但到目前为止找不到任何有用的东西(BasicDataSource)。
更新:以下线程是相关的,但我无法消化我正在寻找的答案,因为 Connection 对象是在 JdbcTemplate 类中获得的,因此不受我的控制。
replacement for jdbc.support.nativejdbc remove in Spring 5
更新 #2 - 堆栈跟踪
Caused by: java.lang.ClassCastException: org.apache.commons.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
at oracle.sql.TypeDescriptor.setPhysicalConnectionOf(TypeDescriptor.java:832)
at oracle.sql.TypeDescriptor.<init>(TypeDescriptor.java:586)
at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:224)
at org.springframework.data.jdbc.support.oracle.SqlArrayValue.createTypeValue(SqlArrayValue.java:90)
at org.springframework.jdbc.core.support.AbstractSqlTypeValue.setTypeValue(AbstractSqlTypeValue.java:60)
at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:293)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:232)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:147)
at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:200)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1048)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1104)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:414)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:397)
at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:193)
更新 #3 - 执行转换的代码 (Oracle JDBC)
public void setPhysicalConnectionOf(Connection var1) {
this.connection = ((oracle.jdbc.OracleConnection)var1).physicalConnectionWithin();
}
【问题讨论】:
标签: java spring-boot jdbc spring-jdbc apache-commons-dbcp