spring-boot: Spring Boot 1.4 : class path resource [] cannot be resolved to URL because it does not exist

The project only indirectly uses components with persistence i.e. there are no entities directly in use. With Spring Boot 1.3.4 there was no need for any kind of persistence configuration. However, upon having upgraded to Spring Boot 1.4 I’ve encountered the following exception:

2016-07-31_19:29:21.758 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at at.oebb.ticketshop.automat.backend.Application.main(Application.java:21) [classes!/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_31]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_31]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [ts-automat-0.0.1.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [ts-automat-0.0.1.jar:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [ts-automat-0.0.1.jar:na]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [ts-automat-0.0.1.jar:na]
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:603) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:443) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    ... 24 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187) ~[spring-core-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:600) ~[spring-orm-4.3.1.RELEASE.jar!/:4.3.1.RELEASE]
    ... 31 common frames omitted

I could fix the issue by the following:

  • @EnableAutoConfiguration(exclude=HibernateJpaAutoConfiguration.class) must be set on the application class
  • spring.data.jpa.repositories.enabled=false must be set in the application properties/yml.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 28 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I have the same problem before. Before upgrading, I was using the starter spring-boot-starter-data-jpa. And the older version is 1.3.5.RELEASE.

With old version 1.3.5.RELEASE, my APP is OK. After upgrading to 1.4.0.RELEASE, my app can not start and report the same problem.

After some debugging, I found the key difference is the maven plugin: spring-boot-maven-plugin.

There has 2 solutions: Solution 1. Force the spring-boot-maven-plugin to use the old version, I am using 1.3.5.RELEASE Solution 2. exclude the jpa dependency: I replace the previous spring-boot-starter-data-jpa to use starter spring-boot-starter-jdbc instead.

The two solution can both fix my problem. But I choose Solution 2 in my app. Because I want to catch up with the newer RELEASE version. And my application doesn’t use jpa function

@andrashatvani I guess mvn spring-boot:run and running your app in the IDE works, it only fails when it’s ran via the fat jar. If so, it would have been nice to say so. If it fails in the IDE, please share a sample because we’re definitely not talking about the same problem.

The problem is the new layout in 1.4 that doesn’t give any fallback options for Spring Framework to compute the persistence unit url. So we’d have to populate setDefaultPersistenceUnitRootLocation with a valid url somehow

(more details for those interested: the way we build the persistence unit makes it so that this URL is actually not used but the JPA implementation has to check that it is specified so we need to give some sort of URL. That’s why this fallback code exists in the first place).