Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot 1.4 : class path resource [] cannot be resolved to URL because it does not exist #6635

Closed
andrashatvani opened this issue Aug 12, 2016 · 28 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@andrashatvani
Copy link

andrashatvani commented Aug 12, 2016

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.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 12, 2016
@snicoll
Copy link
Member

snicoll commented Aug 12, 2016

@andrashatvani that's not helping much I am afraid. On #6314 I asked for more details and the stacktrace doesn't give us anything that we don't know already. A sample that reproduces the problem and illustrates why it's not the same thing as #6314 would help.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 12, 2016
@linzhaoming
Copy link

linzhaoming commented Aug 12, 2016

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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 12, 2016
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Aug 12, 2016
@cbelleza
Copy link

cbelleza commented Aug 12, 2016

If you have an EntityManagerFactory without a real package folder with entities defined this error happens.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 12, 2016
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Aug 13, 2016
@jeesun
Copy link

jeesun commented Aug 15, 2016

@linzhaoming Thank you.With your solution 2,i succeed to run the jar my application generated.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 15, 2016
@snicoll snicoll added for: team-attention An issue we'd like other members of the team to review type: bug A general bug and removed status: feedback-provided Feedback has been provided for: team-attention An issue we'd like other members of the team to review labels Aug 16, 2016
@snicoll snicoll self-assigned this Aug 17, 2016
@snicoll snicoll added this to the 1.4.1 milestone Aug 17, 2016
@snicoll snicoll added type: regression A regression from a previous release and removed type: bug A general bug labels Aug 17, 2016
@snicoll
Copy link
Member

snicoll commented Aug 17, 2016

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

@snicoll
Copy link
Member

snicoll commented Aug 22, 2016

I am trying to define an URI that makes sense. Based on @wilkinsona's feedback, I am trying to get the location of the main Spring Boot application class. I've implemented something that is ok-ish. Unfortunately, Hibernate does not like it:

java.io.FileNotFoundException: /Users/snicoll/workspace/scratches/test-jpa-no-entities/target/test-jpa-no-entities-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
        at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_92]
        at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_92]
        at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_92]
        at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_92]
        at java.util.jar.JarFile.<init>(JarFile.java:103) ~[na:1.8.0_92]
        at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.resolveJarFileReference(JarFileBasedArchiveDescriptor.java:165) ~[hibernate-core-5.0.9.Final.jar!/:5.0.9.Final]
        at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:51) ~[hibernate-core-5.0.9.Final.jar!/:5.0.9.Final]
        at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59) ~[hibernate-core-5.0.9.Final.jar!/:5.0.9.Final]
        at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:47) ~[hibernate-core-5.0.9.Final.jar!/:5.0.9.Final]

I am running out of options there... A FailureAnalyzer is my next solution but it would be nice if we could prevent that exception from happening in the first place.

@jhoeller
Copy link

Persistence providers expect a jar file reference there, which is why DefaultPersistenceUnitManager adapts any such URI through ResourceUtils.extractJarFileURL first. This might work here as well.

@snicoll
Copy link
Member

snicoll commented Aug 23, 2016

I should note for the record that @jhoeller gave me that trick last week and I already forgot about it. Thanks Juergen, tried that and it worked. The code requested to get that working is a bit convoluted so I'll push that to a branch and check with the team what we can do to improve it.

@philwebb
Copy link
Member

I'm a little worried that the new ApplicationInfo class will end up being SpringApplication lite. I wonder if we should either expose a much more limited ApplicationMainClass bean, or alternatively just directly publish SpringApplication itself as a bean?

I have some reservation about the second option.

@philwebb philwebb reopened this Aug 29, 2016
@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Aug 29, 2016
@snicoll
Copy link
Member

snicoll commented Aug 29, 2016

I, for sure, didn't want to expose SpringApplication. It's mutable and most the stuff you'd change there once the app has started would have no effect. Maybe ApplicationInfo could be an interface that SpringApplication implements? This would still allow you to get the implementation though.

@philwebb
Copy link
Member

I have the same concerns about exposing SpringApplication.

philwebb added a commit to philwebb/spring-boot that referenced this issue Aug 29, 2016
Rework commit 4a69755b to remove the need for the ApplicationInfo class.
The updated code now registers the main application class directly as
a bean which is picked up by JpaBaseConfiguration.

Closes spring-projectsgh-6635
@philwebb
Copy link
Member

I think we should hold off on adding the ApplicationInfo class for now. I've reworked things in https://github.com/philwebb/spring-boot/tree/gh-6635 to register the main application class directly as a bean instead.

@snicoll
Copy link
Member

snicoll commented Aug 30, 2016

This goes in the opposite direction of not adding too much singleton beans to the context. I can see some serious improvements in that commit but registering the class as a singleton is not one of them IMO.

@snicoll snicoll removed the for: team-attention An issue we'd like other members of the team to review label Aug 31, 2016
@snicoll
Copy link
Member

snicoll commented Aug 31, 2016

I've reworked your proposal and removed the registration of the main application class. We're using the class of the auto-configuration now. I've also reverted the other changes related to ApplicationInfo in the documentation and the remote shell support. Those two commits combined adds a minimal change in the builder and JpaBaseConfiguration. Thanks a lot for polishing the initial proposal!

@znikola
Copy link

znikola commented Sep 24, 2016

I've seen that fix to this issue has been included in 1.4.1 release, but after upgrade I'm still having this problem.

Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist

EDIT: We are using hbm.xml files for our entity mapping, which means that we have POJO classes as a model without any annotation in them. But, we are using Spring Data JPA repositories.

@wilkinsona
Copy link
Member

@znikola Are you sure you've successfully upgraded to 1.4.1.RELEASE? I cannot reproduce the problem any more. If you can, please open a new issue with a sample that shows how to do it and we'll take a look.

@znikola
Copy link

znikola commented Sep 26, 2016

Yes, upgrade was successful and everything is cleaned and rebuild again. I'll create new project on GitHub and just link it in new issue, so that you can reproduce it. Is that OK?

@wilkinsona
Copy link
Member

I'll create new project on GitHub and just link it in new issue, so that you can reproduce it. Is that OK?

Perfect. Thank you.

@znikola
Copy link

znikola commented Sep 27, 2016

@wilkinsona I uploaded project in this (#6983) issue since it could be related.

Sorry that this took so long to respond.

@fjordansilva
Copy link

Same issue for me using Spring Boot 1.4.1.RELEASE
I'm trying to load an external properties file placed in the same folder as the app uber jar.

@wilkinsona
Copy link
Member

@fjordansilva That doesn't sound like the same issue to me. This issue is specifically related to JPA and loading an external properties file should not be affected. If you need some help with that, I'd recommend posting a question on Stack Overflow.

@fjordansilva
Copy link

Ok, thanks, I'll do it

philwebb added a commit that referenced this issue Oct 31, 2016
Update JpaBaseConfiguration so that the persistenceUnitRootLocation is
no longer detected. The update to gh-7003 means that we can now rely on
the standard detection mechanism.

Fixes gh-6983
See gh-6635
@patexoid
Copy link

Got the same issue on 1.4.2.RELEASE.
1.4.1.RELEASE works fine
full log https://travis-ci.org/patexoid/ZombieLib2/jobs/175686754

@snicoll
Copy link
Member

snicoll commented Nov 14, 2016

@patexoid that looks weird and this issue is closed anyway. Please create a new issue with a sample that reproduces the issue since we've been investigating quite a lot of use cases and apparently you found yet another one.

crain added a commit to crain/reporting that referenced this issue Jul 7, 2017
Add dummy entity to give EntityManagerFactory a package folder to load entities. This is a workaround to prevent an error described here: spring-projects/spring-boot#6635
Extract string fields into constants
Add needed property files for OWASP library
Removed example migration sql
@nmorado
Copy link

nmorado commented Jul 21, 2017

seems like an issue in 1.5.4.RELEASE?

@wilkinsona
Copy link
Member

@nmorado As shown by the fact that this issue is closed, we believe it is fixed. If you think that's not the case please open a new issue with a sample that reproduces the problem.

pradithya added a commit to pradithya/microservices-demo that referenced this issue Feb 17, 2018
michael-3-141 added a commit to michael-3-141/fineract-import-default-setup that referenced this issue Aug 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests