我按照 开发指南上的方法配置了下 运行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>帮帮忙啊谢谢了 啊
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>帮帮忙啊谢谢了 啊
解决方案 »
- js,除处空格问题
- filter 问题 过滤器熟悉的高手进
- 我想用jbuilder2005开发jsp网页。还没有开始呢,怎么回出现这个问题?
- [求助]关于在静态的页面当中加入动态内容
- <html:radio property="sex" value="1"/>
- jsp页面中文全部变成问号
- 如何在JBuilder 7当中使用Tomcat4.1.18作为WEB调试环境?
- 关于分页问题(我看了以前的讨论. 但都不行)
- 谁知道类似于my.sina.com.cn和cn.my.yahoo.com中的版面个性化定制的原理是什么?
- 怎么在谷歌浏览器上实现网页指纹登陆
- 分页问题,谁有好的解决方案啊?急求
- JSP生成EXCEL的问题!
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>
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
你的personDAO bean的配置文件是这样写的,但是你的personDAO的代码中没有sessionFactory这个属性,或者这个属性没有setter函数报错说明向personDAO注入该属性失败,这个属性不可写
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>
class="com.cbitech.testlogin.service.PersonManagerImpl">
<property name="personDAO">
<ref local="personDAO" />
</property>
</bean>
就是在 com.cbitech.testlogin.service.PersonManagerImpl这个类里有personDAO和他的get
set就可以了吧 我写过了啊
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;
}}
class="com.cbitech.testlogin.service.PersonManagerImpl">
<property name="personDAO">
<ref local="personDAO" />
</property>
</bean>
还有一个地方有可能有问题,把personManagerTarget属性personDAO改成personDao看看,这个和本地的bean personDAO重名
<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;
}上下的类型不相符
是我把personDao名字写错了