4

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

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...

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!

  • What's your motivation for using the module system? There's minimal, if any benefit in using it when building a Spring Boot application that will be packaged as a self-contained executable jar file. – Andy Wilkinson Dec 01 '18 at 16:17
  • Mainly just learning - that's a home project. Though still, something is not quite right, it should be running, so I might miss something. – Peter Kovacs Dec 01 '18 at 16:37
  • I just had this issue in a totally different context, thought I'd give my 2 cents: We have a spring boot application, runs fine, but I tried to run "mvn install" from another folder; the unit tests failed. So I guess there may be an issue with Spring when compiling/running by specifying folders, as your IDE might probably do. – Saucistophe Jan 08 '19 at 08:28

2 Answers2

4

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;
  • 1
    Adding java.xml.bind does not resolve this issue.. In fact, adding `requires net.bytebuddy;` did actually help – Gondy Nov 02 '19 at 16:40
1

Add following into your module-info.java:

requires net.bytebuddy;
Gondy
  • 4,925
  • 4
  • 40
  • 46