【发布时间】:2016-05-20 01:10:07
【问题描述】:
我有一个 SpringBoot 应用程序(Java 8 上的 1.3.2.RELEASE),它通过 JDBC 对 Oracle JDBC 驱动程序 12.1.0.1 使用 Hibernate 4.3.11.Final 和 SQL 调用。它也使用hibernate-c3p0 4.3.11.Final。 JDBC 调用是针对自动装配的 JdbcTemplate 实例进行的。
在我的 pom 中,我还依赖于 Oracle UCP 和 ONS。以下是相关的 pom 条目:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ucp</artifactId>
<version>12.1.0.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ons</artifactId>
<version>12.1.0.2</version>
</dependency>
但是,我找不到 Oracle UCP 的配置。此外,c3p0 的所有配置似乎只适用于 Hibernate。
以下是相关的 application.properties 文件条目(没有其他属性文件):
# Properties for Hibernate and Oracle
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@my-db-server:1523:me
spring.datasource.username=myuser
spring.datasource.password=mypass
# Configure the C3P0 database connection pooling module
spring.jpa.properties.hibernate.c3p0.max_size = 15
spring.jpa.properties.hibernate.c3p0.min_size = 6
spring.jpa.properties.hibernate.c3p0.timeout = 2500
spring.jpa.properties.hibernate.c3p0.max_statements_per_connection = 10
spring.jpa.properties.hibernate.c3p0.idle_test_period = 3000
spring.jpa.properties.hibernate.c3p0.acquire_increment = 3
spring.jpa.properties.hibernate.c3p0.validate = false
spring.jpa.properties.hibernate.c3p0.numHelperThreads = 15
spring.jpa.properties.hibernate.connection.provider_class = org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.connection.url=jdbc:oracle:thin:@sea-db-server:1523:me
spring.jpa.properties.hibernate.connection.username=myuser
spring.jpa.properties.hibernate.connection.password=mypass
我想弄清楚的是,针对 spring autowired JdbcTemplate 进行的 JDBC 调用是否正在使用 c3p0 连接池,以及 Oracle UCP 是否正在做任何事情,因为它似乎没有配置.
我真的需要 JDBC 调用的连接池。现在,我遇到了与 Oracle 的连接关闭的问题。我们没有使用 Oracle RAC,所以我不需要 UCP,因此可以只使用 c3p0。
如果有人可以帮助我了解现在正在发生的事情,或者告诉我要检查什么,我将不胜感激。另外,假设我是对的并且 JDBC 调用没有使用池,那么解决这个问题的最佳方法是什么?
更新
根据下面的答案和 cmets,我决定删除 c3p0 并使用 Spring 原生支持的池。因此,我将从 pom 中提取 c3p0(以及 oracle ucp 和 ons),并在 application.properties 文件中包含以下内容。
我正在尝试确保 (1) 我有一个连接池,如果连接丢失,我将管理与数据库的重新连接,以及 (2) JDBC 和 Hibernate 使用相同的数据源。
我做对了吗?
spring.datasource.url=jdbc:oracle:thin:@db-server:1523:mysvc
spring.datasource.username=myuser
spring.datasource.password=mypass
spring.datasource.max-active=50
spring.datasource.initial-size=5
spring.datasource.max-idle=10
spring.datasource.min-idle=5
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=true
spring.datasource.validation-query=SELECT 1 FROM DUAL
spring.datasource.time-between-eviction-runs-millis=5000
spring.datasource.min-evictable-idle-time-millis=60000
【问题讨论】:
标签: hibernate jdbc spring-boot c3p0