我知道互联网上有很多解决方案,但似乎没有什么对我有用。
我的 jdk11 应用程序的 pom.xml 文件中有以下条目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
</parent>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.1.0.0</version>
</dependency>
<dependency>
<groupId>com.oracle.database.ha</groupId>
<artifactId>ons</artifactId>
<version>21.1.0.0</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ucp</artifactId>
<version>21.1.0.0</version>
</dependency>
我正在使用配置如下的连接池
platform: oracle
url: jdbc:oracle:thin:@localhost:1521:TEST
connectionFactoryClassName: oracle.jdbc.pool.OracleDataSource
fastConnectionFailoverEnabled: true
username: test
password: test
initialPoolSize: 3
minPoolSize: 0
maxPoolSize: 12
inactivityTimeout: 300
queryTimeout: 600
validateConnectionOnBorrow: true
我只查询表没有添加或更新到 oracle 记录,像这样
PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource();
@Bean
public DaoSpringJdbcImpl listenerDAO(final DataSource dataSource ) {
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource );
DaoSpringJdbcImpl listenerDAO = new DaoSpringJdbcImpl(template);
return listenerDAO;
}
public class DaoSpringJdbcImpl {
private NamedParameterJdbcTemplate jdbcTemplate;
public DaoSpringJdbcImpl(NamedParameterJdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void method() {
List<String> results = jdbcTemplate.query(SQL_QUERY, params,
new RowMapper<String>()
{
public String mapRow(ResultSet rs, int rowNum) throws SQLException
{ return rs.getString(0)}
}
}
所以每次我的应用程序查询它都会打开新的游标并且永远不会关闭它最终导致打开游标异常
PS我尝试添加 env 属性 spring.jdbc.getParameterType.ignore = true 没有工作