我有一个应用程序,该应用程序使用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;
}
如果有人对这个问题有任何想法,请不要犹豫将其写下来-在这一点上,我基本上陷入了困境。提前非常感谢您!
答案 0 :(得分:2)
我遇到了相同的错误,并且设法通过添加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;
答案 1 :(得分:1)
在您的module-info.java
中添加以下内容:
requires net.bytebuddy;