簡體   English   中英

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

[英]Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] in xml configuration file

我正在學習如何在Spring項目中使用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

我認為您可以使用org.springframework.orm.hibernate5.LocalSessionFactoryBean及其“ annotatedClasses ,“ annotatedPackages或“ packagesToScan屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM