使用SSH框架,出现BeanCreationException错误

J2EE 码拜 9年前 (2015-04-02) 1674次浏览 0个评论

org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”serviceActionBean”” defined in ServletContext resource [/WEB-INF/bean.xml]: Cannot resolve reference to bean “”serviceDao”” while setting bean property “”serviceDao””; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”serviceDao”” defined in ServletContext resource [/WEB-INF/bean.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property “”sessionFactory”” of bean class [com.swu.dao.impl.ServiceDao]: 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?
 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”serviceDao”” defined in ServletContext resource [/WEB-INF/bean.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property “”sessionFactory”” of bean class [com.swu.dao.impl.ServiceDao]: 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?
 Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property “”sessionFactory”” of bean class [com.swu.dao.impl.ServiceDao]: 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?

bean.xml 使用SSH框架,出现BeanCreationException错误

其他层代码:
使用SSH框架,出现BeanCreationException错误
使用SSH框架,出现BeanCreationException错误
使用SSH框架,出现BeanCreationException错误

使用SSH框架,出现BeanCreationException错误
是不是dao的注入有问题啊。
使用SSH框架,出现BeanCreationException错误
没给HibernateDaoSupport 注入SessionFactory 或者HibernateTemplate
使用SSH框架,出现BeanCreationException错误
补充:我第一个userActionBean 的注入是没问题的,用户可以正常注册登录,第二个serviceActionBean注入就出现了问题,求解决
使用SSH框架,出现BeanCreationException错误
既然都是spring注入,为何有new对象了,new对象。。。。
使用SSH框架,出现BeanCreationException错误
你的ServiceAction类中,ServiceDao 改成IServiceDao,也就是改成接口,试一下。
使用SSH框架,出现BeanCreationException错误
你的service 为何没有setter方法?
使用SSH框架,出现BeanCreationException错误
而且你的 serviceAction 应该加上 scope = “”prototype””,否则存在线程安全问题
使用SSH框架,出现BeanCreationException错误
引用 7 楼 IBelieve_ICanFly 的回复:

而且你的 serviceAction 应该加上 scope = “”prototype””,否则存在线程安全问题

请教一下scope = “”prototype””会存在哪些线程安全问题。

使用SSH框架,出现BeanCreationException错误
10分
引用 8 楼 baohuan_love 的回复:
Quote: 引用 7 楼 IBelieve_ICanFly 的回复:

而且你的 serviceAction 应该加上 scope = “”prototype””,否则存在线程安全问题

请教一下scope = “”prototype””会存在哪些线程安全问题。

Sping容器管理的bean,默认是单例的,那么在serviceAction 里面有一个共享属性Service,多线程访问的时候Service的属性就可能同时被多个线程修改,所以会破坏了数据的完整性
加上scope = “”prototype””,就是原型模式,也就相当于每次调用的时候new一个对象了
另外sessionFactory的配置是怎样的

使用SSH框架,出现BeanCreationException错误
补充:我的这个项目放在其他人的电脑上是不会报错,可以直接运行的,而在我这就会报上面的错,Java环境,tomcat我都换过了,没用,真不知道是为什么,哪里配置出了问题
使用SSH框架,出现BeanCreationException错误
困扰我一个星期的问题终于解决了,的确是因为单例模式造成的,加上 scope=””prototype”” 属性之后就不会再报错了,7楼大神,谢谢了。
使用SSH框架,出现BeanCreationException错误
引用 7 楼 IBelieve_ICanFly 的回复:

而且你的 serviceAction 应该加上 scope = “”prototype””,否则存在线程安全问题

是不是所有的bean都应该加上scope=””prototype””这个属性,还有为什么其他人电脑上不会报错呢?

使用SSH框架,出现BeanCreationException错误
30分
引用 11 楼 LFhappypain 的回复:

困扰我一个星期的问题终于解决了,的确是因为单例模式造成的,加上 scope=””prototype”” 属性之后就不会再报错了,7楼大神,谢谢了。

谢谢不给分吗? 哥是新手,还没得过分呢

使用SSH框架,出现BeanCreationException错误
引用 12 楼 LFhappypain 的回复:
Quote: 引用 7 楼 IBelieve_ICanFly 的回复:

而且你的 serviceAction 应该加上 scope = “”prototype””,否则存在线程安全问题

是不是所有的bean都应该加上scope=””prototype””这个属性,还有为什么其他人电脑上不会报错呢?

所有的Action 都得加上, 什么叫存在线程安全问题? 存在, 是隐患, 当并发操作Action 时会出现问题


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用SSH框架,出现BeanCreationException错误
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!