【发布时间】:2022-01-24 20:30:16
【问题描述】:
我有一个项目使用了 grails 框架 3.X 和 Oracle DB,并且该项目部署在 tomcat 9.0.X 上。
项目存在DB连接问题,当项目与DB之间的连接、防火墙或任何网络配置发生变化时,DB连接中断,项目无法自动重新连接DB;或 DB 的设置已更改或 DB 已重新启动。正因为如此,现在,当这个问题发生时,我手动将项目重新部署在 tomcat 服务器上。
为了解决这个问题,我尝试了很多改变,但问题还没有消失。例如,我在 application.yml 上更改了 dataSource 配置的属性,并尝试了不同版本的 OJDBC 驱动程序。
当我在 application.yml 上将“pool”的值从 true 更改为 false 时,中断的连接可以自动重新连接。但是,我认为“pool: false”配置会产生负面影响,因为数据库连接操作很昂贵。例如,要达到最大连接限制,...
所以,我的问题是,当数据库连接中断时,如何在 Oracle 数据库和 grails 项目上进行自动池重新连接?
我目前在application.yml上的配置(可能因为测试有些属性发生了变化):
dataSources:
dataSource:
pooled: true
jmxExport: true
driverClassName: oracle.jdbc.OracleDriver
environments:
development:
dataSources:
dataSource:
logSql: false
dbCreate: update
url: jdbc:oracle:thin:@localdomain:1521/test
username: test
password: test
properties:
maxActive: 50
maxIdle: 25
minIdle: 1
initialSize: 5
numTestsPerEvictionRun: 3
maxWait: 1000
testOnBorrow: true
testWhileIdle: true
testOnReturn: true
minEvictableIdleTimeMillis: 1000
timeBetweenEvictionRunsMillis: 1000
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 5
validationInterval: 5
removeAbandoned: true
removeAbandonedTimeout: 5
production:
dataSources:
dataSource:
dbCreate: none
jndiName: "java:comp/env/testDs"
properties:
maxActive: 50
maxIdle: 25
minIdle: 1
initialSize: 5
numTestsPerEvictionRun: 3
maxWait: 1000
testOnBorrow: true
testWhileIdle: true
testOnReturn: true
minEvictableIdleTimeMillis: 1000
timeBetweenEvictionRunsMillis: 1000
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 5
validationInterval: 5
removeAbandoned: true
removeAbandonedTimeout: 5
【问题讨论】:
-
你能说一下你试过哪个版本,你的数据库是什么版本?
-
@Codebling 我已经尝试了几个版本的 OJDBC8。数据库版本是 12c (12.1)。
-
您可以尝试将
oracle.net.DOWN_HOSTS_TIMEOUT更改为 1(秒)。也可以将oracle.net.keepAlive设置为true。 OracleConnection settings。 Grails 使用什么连接池? -
我项目的连接池设置是默认的。据我了解,连接池是Tomcat JDBC Pool。
-
Grails默认的ORM是Hibernate ORM。
标签: java oracle tomcat grails ojdbc