Error creating bean with name 'loginBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'sessionFactory' of bean class [com.enorth.lichen.action.JzUserLoginAction]: No property 'sessionFactory' found
在applicationContext.xml中的对应<bean>设置中加入scope="prototype"
- <beanid="loginBean"class="com.enorth.lichen.action.JzUserLoginAction"
- abstract="false"lazy-init="default"autowire="default"
- dependency-check="default"scope="prototype">
scope="prototype"作用:
这样配置后就表明每次从spring容器中获取Action的实例的时候就会new一个新对象,即我们所说的原型,spring中scope默认的是单态(singleton),当然针对web应用程序,还可以配置为request、session等范围。至于什么时候使用什么权限范围就要看应用程序的使用了,比如在多线程程序中,单态是否会对程序有所影响就需要考虑了。
Invalid property 'sessionFactory' of bean class [com.enorth.lichen.action.JzUserLoginAction]: No property 'sessionFactory' found
在对应Action中加入sessionfactory的set方法:
- privateSessionFactorysessionFactory;
- publicSessionFactorygetSessionFactory(){
- returnsessionFactory;
- }
- publicvoidsetSessionFactory(SessionFactorysessionFactory){
- this.sessionFactory=sessionFactory;