首页 > 解决方案 > bean 类 [com.zaxxer.hikari.HikariConfig] 的无效属性“url”

问题描述

我是弹簧框架的新手。我在 spring MVC(版本 4)+ hibernate(版本 4)框架应用程序中使用 Hikari 创建一个连接池。运行我的应用程序时出现以下错误。

 Invalid property 'url' of bean class [com.zaxxer.hikari.HikariConfig]: Bean property 'url' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

调度程序-servelt.xml:

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
            <constructor-arg ref="hikariConfig" />
        </bean>

        <!-- HikariConfig config that is fed to above dataSource -->
        <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
                <property name="driverClassName" value="${postgres.driver}" />
                <property name="url" value="${postgres.url}?stringtype=unspecified" />
                <property name="username" value="${postgres.user}" />
                <property name="password" value="${postgres.password}" />
                <property name="maximumPoolSize" value="${hikari.maximumPoolSize}" />
                <property name="idleTimeout" value="30000" />
        </bean>

        <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
                <property name="dataSource" ref="dataSource" />
                <property name="packagesToScan">
                    <array>
                        <value>XXXX</value>
                        <value>XXXX</value>
                    </array>
                </property>
                <property name="hibernateProperties">
                    <props>
                        <prop key="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</prop>
                        <prop key="hibernate.dialect">${postgres.hibernate.dialect}</prop>
                        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                        <prop key="hibernate.jdbc.batch_size">20</prop>
                        <prop key="hibernate.order_inserts">true</prop>
                        <prop key="hibernate.order_updates">true</prop>
                        <prop key="hibernate.jdbc.batch_versioned_data">true</prop>
                    </props>
                </property>
         </bean>

hibernate.properties 文件:

hibernate.show_sql=true
hibernate.hbm2ddl.auto=create/update
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=5
hibernate.hikari.maximumPoolSize=10
hibernate.hikari.idleTimeout=25200
hibernate.hikari.connectionTimeout=25200
hibernate.hikari.dataSourceClassName=org.postgresql.Driver
hibernate.hikari.dataSource.url=XXXX
hibernate.hikari.dataSource.user=XXXX
hibernate.hikari.dataSource.password=XXXX
hibernate.CharSet=true
hibernate.characterEncoding=true
hibernate.useUnicode=true

pom.xml:

            <dependency>
                <groupId>com.zaxxer</groupId>
                <artifactId>HikariCP</artifactId>
                <version>3.4.5</version>
            </dependency>

java版本:8,tomcat:8.5

标签: javaspringhibernateconnection-poolinghikaricp

解决方案


推荐阅读