我有一个应用程序,它将Spring Boot和Spring Data JPA与基于注释的配置一起用于其持久层。我已经开始将此应用程序迁移到最新的Spring Boot版本(2.1.x)和Java (OpenJDK) 11。在配置模块描述符之后,应用程序将启动,但当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;
}如果任何人对这个问题有什么想法,请不要急于写下来--我基本上就卡在这一点上了。非常感谢您的提前!
发布于 2019-03-14 04:48:32
我也遇到了同样的错误,我设法通过添加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;发布于 2019-11-03 00:41:45
在您的module-info.java中添加以下内容
requires net.bytebuddy;https://stackoverflow.com/questions/53572630
复制相似问题