簡體   English   中英

用OpenJpa Spring-Boot Rest替換hibernate

[英]Replace hibernate with OpenJpa Spring-Boot Rest

我是Spring-Boot的新手,目前正在使用現有的Spring-boot REST應用程序中的OpenJPA替換Hibernate。 當我替換pom.xml中的依賴項時,它給出一個錯誤,“ ***************************應用程序無法啟動*** ************************

Description:

Parameter 0 of constructor in com.emp.service.CarhireEventService required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.


Process finished with exit code 1"

下面是修改后的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>hibernate-entitymanager</artifactId>
                <groupId>org.hibernate</groupId>
            </exclusion>
        </exclusions>

</dependency>

<dependency>
    <groupId>org.apache.openjpa</groupId>
    <artifactId>openjpa-all</artifactId>
    <version>2.4.0</version>
</dependency>

下面是主班

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class EmpApplication {

    public static void main(String[] args) {
        SpringApplication.run(EmpApplication.class, args);
    }
}

下面是carhireEventService類

@Service
public class CarhireEventService {

    private CarhireEventRepository carhireEventRepository;

    @Autowired
    public CarhireEventService(CarhireEventRepository carhireEventRepository) {
        this.carhireEventRepository = carhireEventRepository;
    }

    public CarhireEvent createCarhireEvent(String equipInitial, Integer equipNum, Date eventDateTime, String evntType) {

        return carhireEventRepository.save(new CarhireEvent(equipInitial, equipNum, eventDateTime, evntType));
    }
}

該應用程序可與Hibernate正常運行。 任何幫助深表感謝。

Spring Boot沒有針對OpenJPA的任何自動配置。 如果要使用它代替Hibernate,則必須自己編寫必要的配置。

暫無
暫無

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

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