org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [dxm.com.dao.imp.UserDaoImp]: 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)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
========================
根据 错误信息提示 显然是 sessionFactory没有get, set方法。加上就ok啦。get方法无所谓,set方法必须有,spring注入注入!!set方法是注入的通道。从方法体就可以看出来。
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
本文探讨了在使用Spring框架时遇到的错误,具体是关于在配置文件中定义bean时设置属性值出现问题的情况。通过分析错误信息,我们发现问题是由于sessionFactory属性未实现get和set方法。为了解决这个问题,文章提供了具体的解决方案,即为sessionFactory属性添加相应的get和set方法,并在实际应用中正确注入。此外,文章还强调了set方法作为注入通道的重要性,以及如何确保参数类型与getter方法返回类型匹配。
1253

被折叠的 条评论
为什么被折叠?



