无法升级到java 17和使用Spring 6的springboot 3.2.5

问题描述 投票:0回答:1

我正在将应用程序从旧版本的 Spring (4) 升级到 Spring 6,并将 Spring Boot 从 2.* 升级到 3.2.5。它可以编译,但由于以下堆栈跟踪,我无法运行它:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: UUID
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-6.1.6.jar!/:6.1.6]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600) ~[spring-beans-6.1.6.jar!/:6.1.6]
    // Additional stack trace
Caused by: java.lang.NoSuchFieldError: UUID
    at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.registerJpaGenerators(StandardIdentifierGeneratorFactory.java:111) ~[hibernate-core-6.4.4.Final.jar!/:6.4.4]
    // Additional stack trace

下面是我的pom.xml文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.spring</groupId>
    <artifactId>bioMedical</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>bioMedical</name>
    <description>Demo project for Spring Boot</description>
    <packaging>war</packaging>
    <properties>
        <java.version>17</java.version>
    </properties>

    <!-- Dependencies -->
</project>


使用 UUID 的唯一类是在 RegisterController 中。这是该课程的相关部分:

package com.spring.bioMedical.Controller;

import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.nulabinc.zxcvbn.Strength;
import com.nulabinc.zxcvbn.Zxcvbn;
import com.spring.bioMedical.entity.User;
import com.spring.bioMedical.service.EmailService;
import com.spring.bioMedical.service.UserService;

@Controller
public class RegisterController {
    // Methods with @RequestMapping annotations
}

任何人都可以帮助确定为什么会出现此错误以及如何修复它吗?

spring spring-boot java-17 entitymanagerfactory
1个回答
0
投票

我最终发现了问题,jakarta.persistence-api 3.0.0 似乎没有 javax.persistence.EntityManagerFactory 的替代品。所以我只是用

 jakarta.persistence-api-3.1.0
替换它,其中包含 jakarta.persistence.EntityManagerFactory

© www.soinside.com 2019 - 2024. All rights reserved.