2016-09-26 28 views
2

我們有一個Spring Boot 1.4.1應用程序,當我們創建runnable jar並嘗試運行它時,我們得到以下堆棧跟蹤:Spring Boot 1.4.1 runnable jar javax.persistence.PersistenceException:無法解析持久性單元根URL

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxEntityManager' defined in class path resource [xxx/web/config/XxxConfig.class]: Invocation of init method failed; nested exception is javax.persistence.Persistenc 
eException: Unable to resolve persistence unit root URL 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE] 
     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE] 
     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE] 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE] 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE] 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE] 
     at xxx.App.main(App.java:48) [classes!/:0.0.1-SNAPSHOT] 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05] 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_05] 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_05] 
     at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_05] 
     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [NES-Web-0.0.1-SNAPSHOT-exec.jar:0.0.1-SNAPSHOT] 
     at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [NES-Web-0.0.1-SNAPSHOT-exec.jar:0.0.1-SNAPSHOT] 
     at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [NES-Web-0.0.1-SNAPSHOT-exec.jar:0.0.1-SNAPSHOT] 
     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [NES-Web-0.0.1-SNAPSHOT-exec.jar:0.0.1-SNAPSHOT] 
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL 
     at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:605) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:445) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:426) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:325) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar!/:4.3.3.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.3.RELEASE.jar!/:4.3.3.RELEASE] 
     at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:602) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE] 
     ... 31 common frames omitted 

我們也發現了這個問題https://github.com/spring-projects/spring-boot/issues/6635,但根據它,這應該是固定在春季啓動1.4.1

注意:我們沒有註釋在我們的模型類,我們使用HBM。 xml文件進行映射。但是,我們使用Spring Data JPA存儲庫。

回答

2

基於方向我讀到這裏(https://github.com/spring-projects/spring-boot/issues/6983#issuecomment-249981782)我設法通過執行以下操作以創建解決此問題:

  1. 我創建META-INF/orm.xml中文件,並把它放在的src/main/resources文件夾。文件的內容可以在此鏈接https://github.com/spring-projects/spring-data-jpa/blob/master/src/test/resources/META-INF/orm.xml(找到你實際上並不需要持久化單元的元數據命名查詢實體標籤,只是一個空洞的XML與根實體-mappings標籤就夠了)。

  2. 在配置LocalContainerEntityManagerFactoryBean豆,我需要調用setPersistenceUnitRootLocation方法和設置位置類路徑:META-INF/orm.xml中

此解決方案運行時發解決地雷問題罐。但是,通過實現這個解決方法,我創建了另一個問題 - 我無法從IDE運行應用程序,因此我必須根據某個指示器實現持久性單元的根位置的某種條件設置,無論是運行jar還是從IDE。

+0

我學到了評論上傳示例項目如何在這裏檢測fat jar模式:http://stackoverflow.com/a/20073154/43392 –

0

您可能受到this regression的影響。問題中提供了一個解決方法。請嘗試並等待1.4.2.RELEASE。對不起:(

+1

斯特凡,我在這一問題 – pegasus

0

我得到了同樣的錯誤用Maven構建-JAR-插件的jar,但建設的jar像以下正常工作:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
    </build> 
相關問題