Skip to content

Package JPA with orm.xml fails with odd error: "cannot be resolved to URL because it does not exist" in Spring-Boot 1.4.0.M2 #5842

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

Closed
pavax opened this issue May 2, 2016 · 13 comments
Labels
type: blocker An issue that is blocking us from releasing type: bug A general bug
Milestone

Comments

@pavax
Copy link

pavax commented May 2, 2016

Since we updated from spring-boot 1.3.3 to 1.4.M2 we receive a odd exception if we start our application by packing it into a execuatable jar (or war). This problem only occurs if you don't scan for any entities in your classpath but rather define the mapping in a orm.xml. The Bug seems to be similar to an already fixed one: #420

Everything works if we start the Application with the Application.java main method or if we deploy the (execuatable) war file to tomcat. The problem does not occur if there has been at least one Entity defined/scanned by using the javax.persistence annotations

Tested Versions
Spring Boot Version 1.4.0.M2
Spring Boot Version 1.3.3 (works)

Exception:

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)
        at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:588)
        ... 31 common frames omitted

Example Project:
https://github.com/pavax/sample-spring-boot-app

Howto

  1. mvn clean install
  2. start the application java -jar sample-spring-boot-app.jar

alternatively: change the packaging of the sample-spring-boot-web to war and active the profile executable-war.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 2, 2016
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 2, 2016
@philwebb philwebb added this to the 1.4.0.M3 milestone May 2, 2016
@philwebb philwebb added the type: blocker An issue that is blocking us from releasing label May 2, 2016
@philwebb
Copy link
Member

philwebb commented May 2, 2016

@wilkinsona Looks like 87fe0b2 removed that hack. We could put it back I guess but I wonder if there's a better way?

@wilkinsona
Copy link
Member

wilkinsona commented May 3, 2016

I think there's a bit more to this one. 87fe0b2 removed the hack but it left the tests that were added in the fix for #420 in place. For example, this passes:

@Test
public void resolveRootPathFromArchive() throws Exception {
    LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
            new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
            getClass().getClassLoader());
    assertThat(loader.getResource("")).isNotNull();
}

@wilkinsona
Copy link
Member

The same problem occurs with a shaded jar so I don't think that LaunchedURLClassLoader, or anywhere in our loader for that matter, is the ideal place to fix this. I'm not sure where the ideal place is, though.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label May 3, 2016
@wilkinsona
Copy link
Member

Tomcat produces a URL for the root of the classpath even when the host is configured with unpackWARs=false and it's loading classes straight from an archive. The URL is of the form jar:file:/path/to/the.war!/WEB-INF/classes/.

@wilkinsona
Copy link
Member

The problem only happens when Boot's JarURLConnection is involved, i.e. when the URL has been obtained from an org.springframework.boot.loader.jar.JarFile.

getResourceFrom(new URL("jar:file:src/test/resources/jars/app.jar!/"));
getResourceFrom(new URL("jar:file:src/test/resources/jars/app.jar!/demo/"));
JarFile jarFile = new JarFile(new File("src/test/resources/jars/app.jar"));
getResourceFrom(jarFile.getUrl());
getResourceFrom(jarFile.getNestedJarFile(jarFile.getEntry("demo/")).getUrl());

private void getResourceFrom(URL url) {
    System.out.println(new URLClassLoader(new URL[] { url }, null).getResource(""));
    System.out.println(
            new LaunchedURLClassLoader(new URL[] { url }, null).getResource(""));
}

The above outputs:

null
null
jar:file:src/test/resources/jars/app.jar!/demo/
jar:file:src/test/resources/jars/app.jar!/demo/
null
null
null
null

For consistency with a standard JarURLConnection, the 7th and 8th entries should be non-null.

@wilkinsona
Copy link
Member

Given that this affects shaded jars (where the class loader is out of Boot's control) I've opened https://jira.spring.io/browse/SPR-14246 to see if a more general purpose fix is possible.

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

SPR-14246 won't be fixed in time for M3. Moving back to RC1.

@wilkinsona wilkinsona modified the milestones: 1.4.0.RC1, 1.4.0.M3 May 11, 2016
@wilkinsona
Copy link
Member

SPR-14246 has been fixed and the sample app works when configured to use Spring Framework 4.3.0.BUILD-SNAPSHOT. Boot's already building against those snapshots so there's nothing more to do to address this issue.

@masrawi
Copy link

masrawi commented Jul 1, 2016

I have the same issue with the current 1.4.0.BUILD-SNAPSHOT. it has to do with having the starter application class not in the root package. with 1.3.5 it works but with the latest build it does not
spring-boot-example-5842.zip

@wilkinsona
Copy link
Member

@masrawi This issue's closed. Can you please open a new one?

@snicoll
Copy link
Member

snicoll commented Jul 1, 2016

@masrawi your project is broken in both 1.3 and 1.4 for me. And I don't think it has anything to do with this issue. @SpringBootApplication(scanBasePackages = "base") is actually exactly the same thing as @ComponentScan({ "base" }) (so it's redundant). If I add @EntityScan("base") to your application, everything is working as expected (see the doc)

@masrawi
Copy link

masrawi commented Jul 4, 2016

@snicoll I know it is redundant. it is just there to demonstrate that both are not working. I never needed to use @EntityScan and it worked in all the projects with 1.3. for me 1.4 is broken as the same setting working with 1.3 is not working anymore

@masrawi
Copy link

masrawi commented Jul 4, 2016

@wilkinsona #6314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: blocker An issue that is blocking us from releasing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants