我按照 开发指南上的方法配置了下 运行junittest后错误为
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDAO' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [net.sf.hibernate.impl.SessionFactoryImpl] to required type [org.hibernate.SessionFactory] for property 'sessionFactory']
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [net.sf.hibernate.impl.SessionFactoryImpl] to required type [org.hibernate.SessionFactory] for property 'sessionFactory'配置文件为  applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/ibatis</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/cbitech/testlogin/domain/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="show_sql">true</prop>
<prop key="hibernate.dialect">
net.sf.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="personDAO" class="com.cbitech.testlogin.dao.PersonDaoHibernate">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="personManagerTarget"
class="com.cbitech.testlogin.service.PersonManagerImpl">
<property name="personDAO">
<ref local="personDAO" />
</property>
</bean> <bean id="personManager"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager" />
</property>
<property name="target">
<ref local="personManagerTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean></beans>帮帮忙啊谢谢了 啊

解决方案 »

  1.   

    你的hibernate是什么版本的,如果用的是hibernate3的话,建议你把下面的那个bean的class属性改成"org.springframework.orm.hibernate3.LocalSessionFactoryBean"试试<bean id="sessionFactory"
    class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="mappingResources">
    <list>
    <value>com/cbitech/testlogin/domain/Person.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="show_sql">true</prop>
    <prop key="hibernate.dialect">
    net.sf.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
    </props>
    </property>
    </bean>
      

  2.   

    你的报错信息说你的personDAO bean中的sessionFactory属性传进去的类型不正确,spring的beanfactory实例化bean实例的时候使用属性编辑器对实例的属性进行类型转化的时候出错了,我怀疑就是sessionFactory的类型问题
      

  3.   

    我改成了org.springframework.orm.hibernate3.LocalSessionFactoryBean 错误变成了org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personManagerTarget' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'personDAO' of bean class [com.cbitech.testlogin.service.PersonManagerImpl]: Bean property 'personDAO' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?大概是什么意思?
      

  4.   

    <bean id="personDAO" class="com.cbitech.testlogin.dao.PersonDaoHibernate">
    <property name="sessionFactory">
    <ref local="sessionFactory" />
    </property>
    </bean>
    你的personDAO bean的配置文件是这样写的,但是你的personDAO的代码中没有sessionFactory这个属性,或者这个属性没有setter函数报错说明向personDAO注入该属性失败,这个属性不可写
      

  5.   

    不好意思阿,刚才看错了,报错信息是这样的:
    Error creating bean with name 'personManagerTarget' defined in class path resource [applicationContext.xml]: 
    是说personManagerTarget bean的属性personDAO注入失败
    <bean id="personManagerTarget"
    class="com.cbitech.testlogin.service.PersonManagerImpl">
    <property name="personDAO">
    <ref local="personDAO" />
    </property>
    </bean>
      

  6.   

    在personManagerTarget bean中确定有personDAO属性及其setter方法
      

  7.   

    <bean id="personManagerTarget"
    class="com.cbitech.testlogin.service.PersonManagerImpl">
    <property name="personDAO">
    <ref local="personDAO" />
    </property>
    </bean>
    就是在 com.cbitech.testlogin.service.PersonManagerImpl这个类里有personDAO和他的get
    set就可以了吧  我写过了啊
      

  8.   

    把你的PersonManagerImpl类的源码贴来看看
      

  9.   

    PersonManagerImpl 代码 如下public class PersonManagerImpl extends HibernateDaoSupport implements
    PersonManager {
    private PersonDao personDao; private static Log log = LogFactory.getLog(PersonManagerImpl.class); public List getAllPerson() {
    return personDao.getAllPerson();
    } ) public Person getPerson(String id) {
    Person person = personDao.getPerson(id);
    if (person == null) {
    log.warn("id" + id + "not found");
    } return person;
    }
    public Person savePerson(Person person) {
    personDao.savePerson(person);
    return person; } public void updatePerson(String id) {
    personDao.updatePerson(id); } public void deletePerson(String id) {
    personDao.deletePerson(id); }
    public PersonDao getPersonDao() {
    return personDao;
    }
    public void setPersonDao(PersonDao personDao) {
    this.personDao = personDao;
    }}
      

  10.   

    <bean id="personManagerTarget"
    class="com.cbitech.testlogin.service.PersonManagerImpl">
    <property name="personDAO">
    <ref local="personDAO" />
    </property>
    </bean>
    还有一个地方有可能有问题,把personManagerTarget属性personDAO改成personDao看看,这个和本地的bean personDAO重名
      

  11.   

    你的装配文件中
    <bean id="personDAO" class="com.cbitech.testlogin.dao.PersonDaoHibernate">
    <property name="sessionFactory">
    <ref local="sessionFactory" />
    </property>
    </bean><bean id="personManagerTarget"
    class="com.cbitech.testlogin.service.PersonManagerImpl">
    <property name="personDAO">
    <ref local="personDAO" />
    </property>
    </bean>但是在代码中却是
    private PersonDao personDao;
    public PersonDao getPersonDao() {
    return personDao;
    }
    public void setPersonDao(PersonDao personDao) {
    this.personDao = personDao;
    }上下的类型不相符
      

  12.   

    你有msn么,即时聊天更方便些
      

  13.   

    我msn [email protected]
    是我把personDao名字写错了