日期:2014-05-18  浏览次数:20722 次

hibernate 4中使用3cp0 Spring找不到对应set方法
错误:
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/hib-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClass' of bean class [org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider]: Bean property 'driverClass' 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.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1429)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1134)

配置:hib-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  http://www.springframework.org/schema/context   
   http://www.springframework.org/schema/context/spring-context-3.2.xsd
">
<context:component-scan  base-package="com.eastred"/>  
 <!-- 自动扫描组件,需要把controller去掉,否则影响事务管理 -->  
<!--  <context:component-scan base-package="com.eastred">  
        <context:exclude-filter type="regex" expression="com.eastred.action.*"/>  
     </context:component-scan>  
 -->
<!-- 支持aop注解 -->
<aop:aspectj-autoproxy />


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean>            
<bean id="dataSource" class="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider">
 <property name="driverClass" value="${jdbc.driverClassName}" />
 <property name="jdbcUrl" value="${jdbc.url}" /> 
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

<property name="autoCommitOnClose" value="true"/>
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
&