在Java 9多模块环境中无法解析持久单元根URL

时间:2018-09-19 19:36:13

标签: spring hibernate spring-data-jpa java-9 jigsaw

我正在尝试用Java 9创建一个Spring Boot Maven多模块应用程序。它可以在不添加Spring Data支持和@Entity类的情况下工作,但是现在它将无法启动。 问题是以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.context@5.0.9.RELEASE/org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.9.RELEASE.jar:na]
at spring.context@5.0.9.RELEASE/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.9.RELEASE.jar:na]
at spring.context@5.0.9.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:na]
at spring.boot@2.0.5.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:na]
at spring.boot@2.0.5.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:na]
at spring.boot@2.0.5.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:na]
at spring.boot@2.0.5.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:na]
at spring.boot@2.0.5.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:na]
at hu.kleatech.jigsaw/hu.kleatech.jigsaw.MainApplication.main(MainApplication.java:18) [classes/:na]
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
at spring.orm@5.0.9.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:637) ~[spring-orm-5.0.9.RELEASE.jar:na]
at spring.orm@5.0.9.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:459) ~[spring-orm-5.0.9.RELEASE.jar:na]
at spring.orm@5.0.9.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:440) ~[spring-orm-5.0.9.RELEASE.jar:na]
at spring.orm@5.0.9.RELEASE/org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328) ~[spring-orm-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.0.9.RELEASE.jar:na]
at spring.beans@5.0.9.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695) ~[spring-beans-5.0.9.RELEASE.jar:na]
... 15 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.0.9.RELEASE/org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195) ~[spring-core-5.0.9.RELEASE.jar:na]
at spring.orm@5.0.9.RELEASE/org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:633) ~[spring-orm-5.0.9.RELEASE.jar:na]
... 20 common frames omitted

在互联网上有一些有关此异常的示例,但它们与我都不相关。我相信多模块Java 9环境会以某种方式导致此问题,因此该问题不会重复出现。

我尝试了所有可能找到并想到的解决方案,甚至尝试手动配置所有内容,没有一个对我有帮助或使我离原因越来越近。但是在这些解决方案中我发现有趣的一件事:当Spring Boot找不到任何@Entity类时,似乎抛出了此异常。因此,我认为@Entity类在某种程度上无法通过模块系统看到。

由于问题似乎与环境有关,因此这是整个项目:(请注意,它处于非常早期的状态,大多数不完整,但至少应该运行)  https://github.com/KleaTech/szakdolgozat

感谢任何帮助,我没有想法。

1 个答案:

答案 0 :(得分:1)

您需要将这些依赖项添加到pom.xml中(或者,如果不使用maven,则以不同的方式提供它们):

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>net.bytebuddy</groupId>
    <artifactId>byte-buddy</artifactId>
    <version>1.9.3</version>
</dependency>

并将它们包含在module-info.java

open module org.demo {
    ...
    requires java.xml.bind;
    requires net.bytebuddy;
}