搭建框架遇到SessionFactory is not writable or has an invalid setter method的问题

来源:互联网 发布:怎么开淘宝天猫店 编辑:程序博客网 时间:2024/05/08 23:40

近几日搭建框架,遇到sessionFactory报错,在Spring配置文件中向dao层中注入时报的错:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [com.first.web.dao.LoginDaoImpl]: Bean property 'sessionFactory' 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.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:924)at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)... 27 more


起初各种百度,有的说是Spring配置文件中扫描包配置出现的问题,有的说是把Spring配置文件中注入sessionFactory那句话去掉(可以尝试一下,去掉,然后用注释的方法注入SessionFactory),都试了试,发现是自己在dao层实现类中,SessionFactory的命名规范问题,写成了:

private SessionFactroy sf

没有与Spring配置文件中的名称保持一致。


总结:

1,注解时,必须配置好扫描包的设置,只有Spring扫描到了 类似@resource @component的时候才会去创建bean。

2,细心。



阅读全文
0 0
原创粉丝点击