在xml配置文件中找不到类[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]

时间:2018-11-08 15:44:08

标签: java spring hibernate

我正在学习如何在春季项目中使用hibernate integration,并尝试遵循以下示例:https://www.journaldev.com/3524/spring-hibernate-integration-example-tutorial

该教程具有pom.xml和其他示例文件,但是我使用start.spring.io初始化程序创建了一个pom.xml文件,并尝试将自己的路径与该教程的示例集成。

因此,当我开始创建context.xml并创建bean时,如本教程所示,idea在库中找不到任何类:

<bean id = "hibernate3AnnotatedSessionFactory"
class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name = "dataSource" ref = "dataSource" />

因此,hibernate3软件包对我不可用,我将软件包hibernate3更改为hibernate5,但是在这种情况下,annotation软件包不可用,并且AnnotationSessionFactoryBean类不可用。


问题

我可以在hibernate 5.v中使用“ AnnotationSessionFactoryBean”,还是已经过时的此类?


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

1 个答案:

答案 0 :(得分:1)

我认为您可以使用org.springframework.orm.hibernate5.LocalSessionFactoryBean及其annotatedClassesannotatedPackagespackagesToScan属性。