gpt4 book ai didi

java - 带有 Java 11 : Unable to resolve persistence unit root URL 的 Spring Boot 2.1

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:31:45 26 4
gpt4 key购买 nike

我有一个应用程序,它使用 Spring Boot 和 Spring Data JPA,并为其持久层配置基于注解的配置。我已经开始将此应用程序与 Java (OpenJDK) 11 一起迁移到最新的 Spring Boot 版本 (2.1.x)。配置模块描述符后,应用程序启动,但是当 Spring 达到它想要构建的地步时持久层,应用程序停止并出现以下异常:

Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at spring.orm@5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:640)
at spring.orm@5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:462)
at spring.orm@5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:443)
at spring.orm@5.1.2.RELEASE/org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328)
at spring.beans@5.1.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
at spring.beans@5.1.2.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
... 16 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
at spring.core@5.1.2.RELEASE/org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)
at spring.orm@5.1.2.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:636)
... 21 common frames omitted

此问题仅在我尝试在 IntelliJ IDEA 中运行应用程序时发生,它通过配置模块路径而不是类路径(如预期)启动 JVM。当我尝试运行打包为可执行 jar 的应用程序时,问题消失了,但正如我注意到的那样,当应用程序从可执行 jar 运行时,模块描述符基本上被忽略了......

我设法发现的是 org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager 找到实体,并将它们存储在持久性单元中,但之后,它会尝试确定持久性单元根 URL,这就是失败发生的地方。没有模块描述符,应用程序有一个类路径,这对 DefaultPersistenceUnitManager 来说就足够了,它将使用目标目录(从 IDEA 运行)或持久性 Maven 模块的 JAR(从可执行 JAR 运行)。

我假设模块描述符中缺少某些内容,因此仅供引用,它看起来像这样:

open module leaflet.app.backend.persistence {
requires java.persistence;
requires java.validation;
requires org.apache.commons.lang3;
requires org.hibernate.orm.core;
requires spring.beans;
requires spring.context;
requires spring.data.commons;
requires spring.data.jpa;
requires spring.tx;

exports hu.psprog.leaflet.persistence.dao;
exports hu.psprog.leaflet.persistence.entity;
exports hu.psprog.leaflet.persistence.repository;
exports hu.psprog.leaflet.persistence.repository.specification;
}

如果有人对这个问题有任何想法,请不要犹豫,把它写下来——我基本上就卡在这一点上了。非常感谢您!

最佳答案

我有同样的错误,我已经通过添加 java.xml.bind 设法解决了它

requires java.persistence;
requires java.validation;
requires java.sql;
requires java.xml.bind;

requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.beans;
requires spring.context;
requires spring.core;
requires spring.data.jpa;
requires spring.data.commons;
requires spring.tx;
requires spring.web;

requires slf4j.api;
requires lombok;
requires net.bytebuddy;
requires tomcat.embed.core;

关于java - 带有 Java 11 : Unable to resolve persistence unit root URL 的 Spring Boot 2.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53572630/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com