Spring Boot控制台应用程序:调用init方法失败;嵌套的异常是java.lang.NoClassDefFoundError:javax / transaction / SystemException

时间:2018-06-27 17:50:07

标签: java hibernate spring-mvc spring-boot spring-data-jpa

我正在使用Spring Boot控制台应用程序。如果我在测试方法中提供一些虚拟数据进行测试,则该应用程序可以正常工作。

但是当我尝试从数据库中获取数据并处理相同的应用程序时。

我遇到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactoryBean' defined in class path resource. Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_91]
    at java.lang.Class.forName(Unknown Source) ~[na:1.8.0_91]
    at org.jboss.logging.Logger$1.run(Logger.java:2554) ~[jboss-logging-3.3.2.Final.jar:3.3.2.Final]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_91]
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529) ~[jboss-logging-3.3.2.Final.jar:3.3.2.Final]
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516) ~[jboss-logging-3.3.2.Final.jar:3.3.2.Final]
    at org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:28) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:24) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<clinit>(EntityManagerFactoryBuilderImpl.java:116) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:51) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    ... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.transaction.SystemException
    at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_91]
    at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_91]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_91]
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_91]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_91]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_91]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_91]
    ... 31 common frames omitted
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    at java.util.zip.ZipFile.read(Native Method) ~[na:1.8.0_91]
    at java.util.zip.ZipFile.access$1400(Unknown Source) ~[na:1.8.0_91]
    at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source) ~[na:1.8.0_91]
    at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(Unknown Source) ~[na:1.8.0_91]
    at java.util.zip.InflaterInputStream.read(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.Manifest$FastInputStream.fill(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.Manifest$FastInputStream.readLine(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.Manifest$FastInputStream.readLine(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.Attributes.read(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.Manifest.read(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.Manifest.<init>(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.JarFile.getManifestFromReference(Unknown Source) ~[na:1.8.0_91]
    at java.util.jar.JarFile.getManifest(Unknown Source) ~[na:1.8.0_91]
    at sun.misc.URLClassPath$JarLoader$2.getManifest(Unknown Source) ~[na:1.8.0_91]
    at java.net.URLClassLoader.defineClass(Unknown Source) ~[na:1.8.0_91]
    at java.net.URLClassLoader.access$100(Unknown Source) ~[na:1.8.0_91]
    ... 38 common frames omitted

我怀疑pom文件可能存在问题。

这是我的pom文件依赖项:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.2.0.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>

<!-- Querydsl dependencies -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>

<!-- Jackson JSON Mapper -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>

<!-- Hikari jdbc data surce -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

<!-- Hikari jdbc data surce -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.el/el-api -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2.1-b04</version>
</dependency>

<!-- Mysql connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>4.10.4</version>
</dependency>
</dependencies>

有人可以指导我哪里出问题了!

谢谢。

2 个答案:

答案 0 :(得分:1)

因为您使用的是Java 8,所以我认为解决方法是将0x05040302作为对javax.transaction-api的依赖项:

pom.xml

您的JAR文件之一也可能已损坏;如果是这种情况,请删除您的<dependency> <groupId>javax.transaction</groupId> <artifactId>javax.transaction-api</artifactId> <version>1.2</version> </dependency> 文件夹并运行.m2

答案 1 :(得分:0)

如果您跟踪异常跟踪,您会注意到原因java.util.zip.ZipException: invalid LOC header (bad signature)看起来像.m2文件夹中的一个或多个jar已损坏。请先运行mvn force update,然后再运行mvn spring-boot。