引起:javax.persistence.PersistenceException:无法解析持久性单元根URL

时间:2018-05-14 06:31:48

标签: java spring-boot gradle war

引起:

  

java.io.FileNotFoundException:类路径资源[]无法解析为URL,因为它不存在

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
group 'batch'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'

bootRun {
addResources = true
}

war {
baseName = 'Batch'
version =  '0.1.0'
manifest {
    attributes 'Main-Class': 'com.Application'
}
}
jar {
manifest {
    attributes 'Main-Class': 'src.main.java.com.Application'
}
}
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.6.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.24'
compile group: 'org.json', name: 'json', version: '20180130'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.6.RELEASE'
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '7.0.82'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.2.4.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.7.4.RELEASE'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.1'
}

使用的技术:

Gradle,Springboot,jdk7

异常追踪:

  

tionConfigEmbeddedWebApplicationContext:在上下文初始化期间遇到异常 - 取消刷新att   empt:org.springframework.beans.factory.BeanCreationException:创建名为' entityManagerFactory'的bean时出错在类路径资源中定义[org / springframework / boot / aut   oconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:无法解析持久化   单位根URL   2018-05-14 21:11:04.427 INFO 3136 --- [main] o.apache.catalina.core.StandardService:停止服务Tomcat   2018-05-14 21:11:04.505 INFO 3136 --- [main] utoConfigurationReportLoggingInitializer:

启动ApplicationContext时出错。要显示自动配置报告,请启用调试日志记录(以--debug开头)

2018-05-14 21:11:04.552 ERROR 3136 --- [main] o.s.boot.SpringApplication:应用程序启动失败

org.springframework.beans.factory.BeanCreationException:创建名称为' entityManagerFactory'的bean时出错在类路径资源中定义[org / springframework / boot / autoconfi gure / orm / jpa / HibernateJpaAutoConfiguration.class]:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:无法解析持久性u nit root URL         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)〜[spring-beans-4.3.2.RELEAS E.jar /:4.3.2.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)〜[spring-beans-4.3.2.RELEASE.j !AR /:4.3.2.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)〜[spring-beans-4.3.2.RELEASE.jar !/:4.3.2.RELEASE]         at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]         在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.R 闻稿]         在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)〜[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)〜[spring-context-4.3.2.RELEASE.ja R /:4.3.2.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)〜[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]         在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)〜[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEA SE]         在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]         在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:313)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)[spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]         在com.Application.main(Application.java:15)[classes!/:na]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_171]         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_171]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_171]         at java.lang.reflect.Method.invoke(Unknown Source)〜[na:1.8.0_171]         在org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)[Batch-0.1.0.war:na]         在org.springframework.boot.loader.Launcher.launch(Launcher.java:87)[Batch-0.1.0.war:na]         在org.springframework.boot.loader.Launcher.launch(Launcher.java:50)[Batch-0.1.0.war:na]         在org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)[Batch-0.1.0.war:na] 引发者:javax.persistence.PersistenceException:无法解析持久性单元根URL         在org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:603)〜[spring-orm -4.3.2.RELEASE.jar /:4.3.2.RELEASE]         在org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:443)〜[spring-orm-4.3.2.RELE ASE.jar /:4.3.2.RELEASE]         在org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424)〜[spring-orm-4.3.2.RELEASE.jar!/ :4.3.2.RELEASE]         在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310)〜[spring-orm-4.3 .2.RELEASE.jar /:4.3.2.RELEASE]         在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)〜[spring-orm-4.3.2.RELEASE.ja R /:4.3.2.RELEASE]         在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)〜[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.REL 缓解]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)〜[spring-beans-4.3.2.REL EASE.jar /:4.3.2.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)〜[spring-beans-4.3.2.RELEAS E.jar /:4.3.2.RELEASE]         ...省略了24个常用帧 引起:java.io.FileNotFoundException:类路径资源[]无法解析为URL,因为它不存在         在org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187)〜[spring-core-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]         在org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:600)〜[spring-orm -4.3.2.RELEASE.jar /:4.3.2.RELEASE]         ...省略了31个常见帧

1 个答案:

答案 0 :(得分:0)

解决方案:

删除

compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.1'

添加了如下所示的课程

@Entity
public class TestEntity {
    @Id
    @GeneratedValue
    private int id;
}