【发布时间】:2015-12-26 07:46:17
【问题描述】:
我正在尝试在我的 Spring Boot 服务器上设置 c3p0。这是我现在的配置
spring.datasource.url=jdbc:mysql://url/db
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.test-on-borrow=true
#spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1
#spring.datasource.time-between-eviction-runs-millis=10000
#spring.datasource.min-evictable-idle-time-millis=30000
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
spring.jpa.properties.hibernate.connection.driver_class=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.connection.url=jdbc:mysql://url/db
spring.jpa.properties.hibernate.connection.username=username
spring.jpa.properties.hibernate.connection.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.show_sql=true
#spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
spring.jpa.properties.hibernate.c3p0.max_size=30
spring.jpa.properties.hibernate.c3p0.min_size=7
spring.jpa.properties.hibernate.c3p0.acquire_increment=1
spring.jpa.properties.hibernate.c3p0.idle_test_period=100
spring.jpa.properties.hibernate.c3p0.max_statements=0
spring.jpa.properties.hibernate.c3p0.max_idle_time=200
spring.jpa.properties.hibernate.c3p0.url=jdbc:mysql://url/db
spring.jpa.properties.hibernate.c3p0.username=username
spring.jpa.properties.hibernate.c3p0.password=password
spring.jpa.properties.hibernate.c3p0.driverClassName=com.mysql.jdbc.Driver
我的问题是我不知道如何告诉 spring.datasource 使用
com.mchange.v2.c3p0.ComboPooledDataSource
我看到的所有 XML 定义都使用了类似的东西
<bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource">
不能在application.properties中设置数据源类型/类吗?
据此
有
spring.datasource.type= # fully qualified name of the connection pool implementation to use
但是按照这个
http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
(和我的 STS).type 选项不存在。这是一个错误还是我应该以不同的方式使用它?
我们将不胜感激您的帮助!
干杯!
【问题讨论】:
-
你的
spring.jpa.properties.hibernate.connection和spring.jpa.properties.hibernate.c3p0没用。 Spring Boot 将注入一个数据源,从而禁用这些属性的使用,因此它们只会为您的application.properties添加空间。我不建议使用 C3P0,它已经很老了,而且有一些缺陷,而是使用曾经支持的默认值之一,例如tomcat-jdbc或HikariCP。这样,只需添加 jar,Spring Boot 就会为您配置它。 -
你要找的属性是Spring Boot 1.3早期版本没有这个。
标签: spring spring-boot datasource c3p0