您的位置:首页 > 移动开发

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

2017-08-09 15:16 453 查看
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-8
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.user=root
jdbc.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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐