无法设置spring.datasource.type [英] Not able to set spring.datasource.type

查看:1477
本文介绍了无法设置spring.datasource.type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的spring boot服务器上设置c3p0.这是我现在的配置

I'm trying to setup c3p0 on my spring boot server. This is my config right now

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使用

My problem is that I can't figure out how to tell spring.datasource to use

com.mchange.v2.c3p0.ComboPooledDataSource

我看到的所有XML定义都使用了类似的内容

All XML definitions I saw use something along the lines of

<bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource">

是否无法在application.properties中设置数据源类型/类?

Is it not possible to set the datasource type/class in application.properties?

据此

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

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选项不存在.这是一个错误还是我应该以不同的方式使用它?

(and to my STS) the .type option doesn't exist. Is this a bug or am I supposed to use this differently?

非常感谢您的帮助!

干杯!

推荐答案

spring.datasource.type已在1.3行中引入,因此您需要Spring Boot 1.3.0.M5来使用该属性(IDE中的内容帮助应为您提供适当的提示).

spring.datasource.type has been introduced in the 1.3 line so you need Spring Boot 1.3.0.M5 to use that property (content assistance in your IDE should have give you the proper hint).

在1.2.x上,您需要自己创建DataSource bean来强制类型,例如

On 1.2.x you need to create the DataSource bean yourself to force the type, something like

@Bean
@ConfigurationProperties("spring.datasource")
public DataSource dataSource() {
   return DataSourceBuilder.create().type(ComboPooledDataSource.class)
            .build();
}

这篇关于无法设置spring.datasource.type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆