Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]:

来源:互联网 发布:mfc编程教程 编辑:程序博客网 时间:2024/05/18 05:21

Error creating bean with name ‘dataSource’ defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ‘classDriver’ of bean class [com.mchange.v2.c3p0.ComboPooledDataSource]: Bean property ‘classDriver’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

配置Spring的数据库链接池时出现这个意思,由于框架的配置会出现很多不同的问题。这里只写我自己遇到的(作为初学者)。
上面这个问题的大概意思是:
数据库连接池存在一个无效的classDriver 属性。
求问之后才知道,数据库连接池是别人制作出来的产品不同的数据库链接池,配置也不相同。
以下是我使用的数据库链接池:
这里写图片描述
而后面的${jdbc.jdbcUrl}等是与我之前配置的db.properties文件里面的内容一一对应。
这里写图片描述

db.properties文件

jdbc.jdbcUrl=jdbc:mysql://localhost:3306/zycrm?characterEncoding=utf-8jdbc.driverClass=com.mysql.jdbc.Driverjdbc.user=rootjdbc.password=root

c3p0连接池的正确配置方法;

<!-- 链接数据库连接池 先开启事物,再链接数据库 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">    <property name="dataSource" ref="dataSource"></property></bean><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">    <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>    <property name="driverClass" value="${jdbc.driverClass}"></property>    <property name="user" value="${jdbc.user}"></property>    <property name="password" value="${jdbc.password}"></property></bean>
阅读全文
1 0