org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/web-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController' defined in ServletContext resource [/WEB-INF/web-config.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/service-config.xml]: Cannot resolve reference to bean 'userDao' while setting bean property 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/dao-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.orm.hibernate4.HibernateTemplate' to required type 'org.springframework.orm.hibernate3.HibernateTemplate' for property 'hibernateTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.orm.hibernate4.HibernateTemplate] to required type [org.springframework.orm.hibernate3.HibernateTemplate] for property 'hibernateTemplate': no matching editors or conversion strategy found
--这么长大神们不一定有耐心看,简单描述就是最终要用到HibernateTemplate的实力去save对象。但是Spring生成它的实例时提示需要的是3的类型的实例,但是我用的org.springframework.orm.hibernate4.HibernateTemplate这个类型,我的spring和hibernate都是用的4版本怎么会让用3的类呢?二楼会贴出配置文件。(换3的会报NoSuchMethod异常,网速查了很多了是版本问题)
------解决思路----------------------
1.我的spring和hibernate都是用的4版本怎么会让用3的类呢?
这个和用spring4版本应该没有关系,听说spring在spring3.1不再支持hibernateTemplate,我猜测是否在spring3.1之后是否都不支持hibernateTemplate呢?
2.你可以这样试一下
去掉下面配置
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
因为不再使用 hibernateTemplate,所以改成 sessionFactory.getCurrentSession(),这里要注意对DetachedCriteria 操作,
把
hibernateTemplate.findByCriteria (DetachedCriteria,first,max) ;
换成
DetachedCriteria.getExecutableCriteria(sessionFactory.getCurrentSession()).setFirstResult(first).setMaxResults(max).list()
直接使用 sessionFactory.getCurrentSession().createCriteria(XXX.class) 代替 DetachedCriteria 是最简单的了.