使用Java 11的Spring Boot 2.1:无法解析持久单元根URL [英] Spring Boot 2.1 with Java 11: Unable to resolve persistence unit root URL

查看:222
本文介绍了使用Java 11的Spring Boot 2.1:无法解析持久单元根URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an application, that uses Spring Boot and Spring Data JPA with annotation-only based configuration for its persistence layer. I've started migrating this application to the latest Spring Boot version (2.1.x) along with Java (OpenJDK) 11. After configuring the module descriptors, the application starts up, but when Spring reaches the point where it wants to build up the persistence layer, the application stops with the following exception:

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运行时,模块描述符基本上被忽略了.

This issue only happens when I try to run the application in IntelliJ IDEA, which starts the JVM by configuring the module path, instead of the classpath (as expected). When I try to run the application packaged as executable jar, the issue is gone, but as I noticed, the module descriptors are basically ignored when the application runs from the executable jar...

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

What I've managed to discover is that the org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager finds the entities, and also stores them in a persistence unit, but after that, it tries to determine the persistence unit root URL, and that's the point where the failure occurs. Without the module descriptors, the application has a classpath, and that's enough for the DefaultPersistenceUnitManager, it will use the target directory (running from IDEA) or the persistence Maven module's JAR (running from executable JAR).

我认为模块描述符中缺少某些内容,因此仅作为参考,它看起来像这样:

I assume there's something I'm missing from the module descriptor, so just for the reference, it looks like this:

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;
}

如果有人对这个问题有任何想法,请不要犹豫将其写下来-在这一点上,我基本上陷入了困境.提前非常感谢您!

If anyone might have something in mind about this issue, please don't hesisate to write it down - I'm basically stuck at this point. Thank you very much in advance!

推荐答案

我遇到了相同的错误,并且通过添加java.xml.bind

I had the same error and I've managed to resolve it by adding 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 11的Spring Boot 2.1:无法解析持久单元根URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆