Error creating bean with name 'userDao'
程序员文章站
2022-04-12 20:59:04
...
[color=red]严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lj.service.IUserService com.lj.controller.UserController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.lj.dao.UserDao.setSessionFactory(org.hibernate.SessionFactory); nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;[/color]
在启动的时候,会报出一堆这样的错误。 所有我们使用Annotation的注入都会被报错。
出现这个错误的原因是Spring对sessionFactory的管理。
这里我们使用了hibernate3.LocalSessionFactoryBean,
但是这个类是不支持对Annotation进行管理的。
也就是说我们没有使用mapping文件比如User.xml文件来进行映射的管理。
这里的解决方法有两种,
1: orm.hibernate3.LocalSessionFactoryBean改成orm.hibernate3.annotation.AnnotationSessionFactoryBean,
后者支持hibernate通过Annotation管理映射。
2: 改成orm.hibernate4.LocalSessionFactoryBean.
这里貌似要使用hibernate4才可以。
总之如果容器启动就看到一堆初始化错误,注入异常的信息,很可能就是这个原因了。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lj.service.IUserService com.lj.controller.UserController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.lj.dao.UserDao.setSessionFactory(org.hibernate.SessionFactory); nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;[/color]
在启动的时候,会报出一堆这样的错误。 所有我们使用Annotation的注入都会被报错。
出现这个错误的原因是Spring对sessionFactory的管理。
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
这里我们使用了hibernate3.LocalSessionFactoryBean,
但是这个类是不支持对Annotation进行管理的。
也就是说我们没有使用mapping文件比如User.xml文件来进行映射的管理。
这里的解决方法有两种,
1: orm.hibernate3.LocalSessionFactoryBean改成orm.hibernate3.annotation.AnnotationSessionFactoryBean,
后者支持hibernate通过Annotation管理映射。
2: 改成orm.hibernate4.LocalSessionFactoryBean.
这里貌似要使用hibernate4才可以。
总之如果容器启动就看到一堆初始化错误,注入异常的信息,很可能就是这个原因了。
上一篇: Could not find setter for ID on class com.iflytek.civilAffairs.pojo.MzywShswcYtwy
下一篇: spring data jpa将@ManyToOne查询从cross join变成left outer join
推荐阅读
-
Error creating bean with name 'entityManagerFactory' defined in class path resource解决方案
-
Error creating bean with name ‘eduChapterController‘: Unsatisfied dependency expressed through field
-
UnsatisfiedDependencyException: Error creating bean with name ‘xxxx‘:
-
springMVC常见错误-解决org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.spring
-
Error creating bean with name
-
Error creating bean with name 'eurekaAutoServiceRegistration'
-
Error creating bean with name报错
-
Error creating bean with name dfdatasource
-
Error creating bean with name ‘sqlSessionFactory‘
-
BeanCreationException: Error creating bean with name ‘requestMappingHandlerAdapter‘