hibernate hikaricp数据源

时间:2016-02-07 16:15:08

标签: java hibernate hikaricp

我尝试将我的webapp的连接池从c3p0更改为hikaricp。

这是我的配置。

<bean id="dataSource"
    class="org.hibernate.hikaricp.internal.HikariCPConnectionProvider">

    <property name="dataSourceClassName" value="${hikari.dataSourceClassName}" />
    <property name="maximumPoolSize" value="${hikari.maximumPoolSize}" />
    <property name="maxLifetime" value="${hikari.maxLifetime}" />
    <property name="idleTimeout" value="${hikari.idleTimeout}" />

    <property name="dataSourceProperties">
        <props>
            <prop key="url">${jdbc.url}</prop>
            <prop key="user">${jdbc.username}</prop>
            <prop key="password">${jdbc.password}</prop>
        </props>
    </property>
</bean>

我收到了错误。

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSourceClassName' of bean class [org.hibernate.hikaricp.internal.HikariCPConnectionProvider]: Bean property 'dataSourceClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:231)
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423)
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
    ... 32 more

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

org.hibernate.hikaricp.internal.HikariCPConnectionProvider不是javax.sql.DataSource。它是Hibernate的内部组件。

将您的配置更改为使用com.zaxxer.hikari.HikariDataSource而不是org.hibernate.hikaricp.internal.HikariCPConnectionProvider