我在我的应用程序中使用 spring hibernate。我使用了所有必需的 jar 文件,但仍然收到 Bean 创建异常,内容如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'voteController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mindtree.service.VoteService com.mindtree.controller.VoteController.voteService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'voteServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mindtree.dao.VoteDao com.mindtree.serviceImpl.VoteServiceImpl.voteDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'voteDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.orm.hibernate3.HibernateTemplate com.mindtree.daoImpl.VoteDaoImpl.hibernateTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
最佳答案
在Java中,从最后一行读取堆栈跟踪,这将是问题的根本原因。如果您通过在类路径中添加相应的 jar 文件来修复 java.lang.NoClassDefFoundError
,那么它将正常工作。
关于java - Bean创建异常, Autowiring 依赖注入(inject)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30860320/