java - Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] in xml configuration file
问题描述
I'm learning how to use hibernate integration
in the spring project and try to follow the example below: https://www.journaldev.com/3524/spring-hibernate-integration-example-tutorial
The tutorial has pom.xml
and other sample files, but I use the start.spring.io
initializer to create a pom.xml
file and try to integrate my path with the example of the tutorial.
So when I came to create context.xml
and createdbean
, as shown in the tutorial, idea
could not find any class in the library:
<bean id = "hibernate3AnnotatedSessionFactory"
class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name = "dataSource" ref = "dataSource" />
Thus, the hibernate3
package is unavailable to me, and I changed the packagehibernate3
to hibernate5
, but in this case the annotation
package is not available, and not available the AnnotationSessionFactoryBean
class to.
Question
Can I use the `AnnotationSessionFactoryBean' in hibernate 5.v, or this class already outdated?
pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<hibernate-version>5.3.7.Final</hibernate-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
<!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="hibernate5AnnotatedSessionFactory"
class="org.springframework.orm.hibernate5.... - AnnotatedSessionFactory not avaiilable
解决方案
我认为您可以使用org.springframework.orm.hibernate5.LocalSessionFactoryBean
and its'annotatedClasses
或属性。annotatedPackages
packagesToScan
推荐阅读
- c# - 执行 inkCanvas1.Strokes.Erase() 后的 WPF-InkCanvas 撤消操作
- java - Cytoscape java:将边缘一直绘制到节点的中心
- c# - c# asp.net 身份和自定义角色
- yii2 - 如何更改 yii2 Query Builder 的数据库名称
- java - 休眠@ManyToOne 映射
- git - Git 提交速度非常慢
- node.js - 'await' 在等待基于 promise 的函数时对此表达式的类型没有影响
- tsql - 将 FIRST_VALUE 与基于另一列的条件一起使用
- typescript - Typescript fluent api builder多个参数(覆盖)不可能
- r - 如何下载和阅读htm。R中的文件