gpt4 book ai didi

spring - 无法转换为 org.hibernate.annotations.common.reflection.MetadataProviderInjector

转载 作者:行者123 更新时间:2023-12-02 11:31:50 28 4
gpt4 key购买 nike

在我的 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>

但是当我运行该项目时,我收到错误:

创建名称为“SignupController”的 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

该项目没有错误..

我必须更新什么才能减少此错误..

最佳答案

转到项目(右键单击)>属性>库

删除所有 jar 。

你有pom.xml文件,这意味着你正在使用maven。

所以,转到终端>找到您的项目然后运行:

mvn clean install

关于spring - 无法转换为 org.hibernate.annotations.common.reflection.MetadataProviderInjector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34715564/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com