当前位置: 首页 > 知识库问答 >
问题:

运行jar但从IDE正常工作时出现Spring Boot错误(Spring boot starter data jpa)

高明辉
2023-03-14

**编辑:当我使用gradle而不是maven它工作正常!,我从start.spring.io生成我的项目

**Edit2:my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>org.mywebsite</groupId>
	<artifactId>myprojectname</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>myprojectname</name>
	<description>xxx</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.0.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-hateoas</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.restdocs</groupId>
			<artifactId>spring-restdocs-mockmvc</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-rest</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

当我从eclipse ide运行我的代码时,它工作正常,但当我将项目打包为. jar并从命令行运行时,它显示此错误,如果我从依赖项中删除spring-boot-starter-data-jpa,它工作正常。

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.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at 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]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT]
        at org.betterworldinternational.TheGoodCards2Application.main(TheGoodCards2Application.java:10) [classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_101]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_101]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_101]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [ward.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [ward.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [ward.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [ward.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:603) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:443) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.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.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:600) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        ... 31 common frames omitted

堆栈跟踪图像

共有1个答案

邓英卓
2023-03-14

抱歉回答晚了。这对像我这样带着这个问题来这里的人会有所帮助。

我在pom中有spring-boot-starter-data-jpa依赖项,但没有带有@Entity注释的实体,在下面添加修复了问题,如评论部分建议的那样

@EnableAutoConfiguration(exclude = HibernateJpaAutoConfiguration.class)

spring.data.jpa.repositories.enabled=false

Spring Boot版本1.4.0

 类似资料:
  • 使用NetBeans 8.1。 我有一个SpringBoot项目,它使用Thymeleaf作为模板,除了在html页面中使用标记外,一切都正常 <代码> 我有一个本地名为“xmlns:th”的error属性不能序列化为XML 1.0,我可以使用thymeleaf函数,如th:each或th:text,但它们总是显示相同的错误,我在键入时无法提供建议,有没有办法解决这个问题?

  • 问题内容: 我正在尝试使用JavaMail API发送电子邮件。我从自解压二进制文件在我的主目录中安装了jdk 1.5。我正在使用Ubintu 9.10 我使用下一条命令编译程序: 〜/ jdk1.5.0_22 / bin / javac -classpath〜/ jdk1.5.0_22 / jre / lib / javamail-1.4.3 / mail.jar:〜/ jdk1.5.0_22

  • 我在1-2年前用libGDX做了一个游戏,我可以在eclipse上运行它,它很有效。当我想导出jar文件时,我转到Export-Runnable jar file-这里我选择package required libraries并导出它。

  • 运行hadoop jar文件时出现以下错误 线程“main”java中出现异常。lang.ClassNotFoundException:hdfs: 位于java。网URLClassLoader 1美元。在java上运行(URLClassLoader.java:366) 。网URLClassLoader 1美元。在java上运行(URLClassLoader.java:355) 。安全AccessC

  • 当我执行<code>java-jar myapp时,我有一个运行正常的应用程序。jar但是当我将它链接到作为进程运行时,我得到了404错误。因此,我制作了一个只包含相关类的gitHub存储库来向您显示错误。你能试着复制它吗? 这是代码https://github.com/alephlm/spring-boot-1.3-error-executable-service 我使用的是 ubuntu 14

  • 我在尝试导出独立应用程序时遇到问题。 当我使用eclise执行它时,它运行正常,但当我试图导出到可运行的jar时,它会给我一些错误。 我的坚持。xml看起来像 它位于src/META-INF/persistence。xml 从终端运行时得到的堆栈跟踪是: 在爪哇。朗,反思一下。方法在组织中调用(未知源)。日食jdt。内部的jarinjarloader。罐式装载机。main(jarsrcloader