引起原因:java.lang.NoSuchMethodError:org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava langCla

引起原因:java.lang.NoSuchMethodError:org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava langCla,第1张

引起原因:java.lang.NoSuchMethodError:org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/ lang / Cla

为了使用最新的依赖项,需要做很多修改。我使用了Spring版本

4.3.1.RELEASE
和Hibernate版本
4.3.11.Final
,还使用了最新版本的依赖关系。

在这里您需要在下面进行更改

hibernate-context.xml

对于hibernate3.0

<bean id="sessionFactory"       p:dataSource-ref="dataSource"      p:configLocation="${hibernate.config}"      p:packagesToScan="org.krams.tutorial"/>

对于Hibernate 4.0.x

<bean id="sessionFactory"       p:dataSource-ref="dataSource"      p:configLocation="${hibernate.config}"      p:packagesToScan="org.krams.tutorial"/>

另外: 对于hibernate3.0

<bean id="transactionManager"       p:sessionFactory-ref="sessionFactory" />

对于Hibernate 4.0

<bean id="transactionManager"       p:sessionFactory-ref="sessionFactory" />

IMP注意: Hibernate 3.5及更高版本包含Hibernate注释。 :您应该删除对的依赖

hibernate-annotations

最新的pom.xml

<properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <java.version>1.8</java.version>        <spring.version>4.3.1.RELEASE</spring.version>        <hibernate.version>4.3.11.Final</hibernate.version>        <commons-digester.version>2.1</commons-digester.version>        <mysql.version>5.1.39</mysql.version>        <poi.version>3.6</poi.version>        <javassist.version>3.20.0-GA</javassist.version>        <c3p0.version>0.9.1.2</c3p0.version>        <persistence-api-version>1.0.2</persistence-api-version>        <logback.version>1.1.2</logback.version>        <slf4j.version>1.7.6</slf4j.version>    </properties>    <dependencies>        <!-- Spring Web and Web MVC -->        <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version>        </dependency>        <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version>        </dependency>        <!-- Spring TX -->        <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version>        </dependency>        <!-- Spring ORM -->        <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version>        </dependency>        <!-- Commons Digester -->        <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>${commons-digester.version}</version>        </dependency>        <!-- Commons Collection -->        <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.1</version>        </dependency>        <!-- Apache POI -->        <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.version}</version>        </dependency>        <!-- CGLib Nodep -->        <dependency> <groupId>cglib</groupId> <artifactId>cglib-nodep</artifactId> <version>3.2.4</version>        </dependency>        <!-- Javassist -->        <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>${javassist.version}</version>        </dependency>        <!-- Hibernate -->        <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <!-- <version>3.3.2.GA</version> --> <version>${hibernate.version}</version>        </dependency>        <!-- Persistent API -->        <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>${persistence-api-version}</version>        </dependency>        <!-- C3PO -->        <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>${c3p0.version}</version>        </dependency>        <!-- MySQL -->        <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version>        </dependency>        <!-- Logging -->        <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version>        </dependency>        <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>${slf4j.version}</version>        </dependency>        <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version>        </dependency>        <!-- Servlet API, JSTL, Standard -->        <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version>        </dependency>        <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version>        </dependency>        <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> <type>jar</type> <scope>compile</scope>        </dependency>        <!-- Junit -->        <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope>        </dependency>    </dependencies>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5676047.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存