在我的spring项目中,我正在使用hibernate访问数据库..
我有
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource" p:packagesToScan-ref="packagesToScan"
p:hibernateProperties-ref="hibernateProperties" />
<util:map id="hibernateProperties">
<entry key="hibernate.show_sql" value="false" />
<!-- <entry key="hibernate.hbm2ddl.auto" value="update" /> -->
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</util:map>
<util:list id="packagesToScan">
<value>com.preeti.myproject</value>
</util:list>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
在pom文件中我有:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
但是当我运行该项目时,我收到了错误:
使用名称&#39; SignupController&#39;:
创建bean时出错Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field:
private com.preeti.myproject.service.UserService
com.preeti.myproject.controller.SignupController.userService
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userService':
Injection of autowired dependencies failed;
Could not autowire field:
private org.hibernate.SessionFactory com.preeti.myproject.hibernate.AbstractHibernateDao.sessionFactory;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in ServletContext
resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed;
nested exception is java.lang.ClassCastException:
org.hibernate.annotations.common.reflection.java.JavaReflectionManager
cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector
当我使用
时 hibernate 3.5.0-final,
hibernate-core-3.5.4-Final,
hibernate-entitymanager-3.5.4-Final,
hibernate-commons-annotations-3.3.0.ga
该项目没有错误..
我必须更新以减少此错误..
答案 0 :(得分:2)
转到project(right click)>properties>libraries
删除所有罐子。
你有 pom.xml 文件,这意味着你正在使用maven。
所以,转到终端&gt;找到你的项目,然后运行:
mvn clean install