无法自动装配bean,我正在使用Spring 3.1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法自动装配bean,我正在使用Spring 3.1相关的知识,希望对你有一定的参考价值。

Root Cause 
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: rinku.pms.bean.UserBean rinku.pms.controller.UserController.userBean; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.HibernateTransactionManager] for bean with name 'txManager' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.HibernateTransactionManager>```


答案

您的类路径没有spring-orm依赖项。如果您使用的是maven,请将其添加到pom.xml或下载spring-orm并将其添加到您的库中]

<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>3.1.0.RELEASE</version>
</dependency>

以上是关于无法自动装配bean,我正在使用Spring 3.1的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot:来自库项目的自动装配 bean

Spring:无法从父上下文自动装配 bean

创建 bean 时出错。注入自动装配的依赖项失败。无法自动装配字段

3.Spring自动装配

Spring Batch Test - 无法自动装配。找不到“JobLauncherTestUtils”类型的 bean

自动装配的 spring bean 不是代理