【发布时间】:2018-09-02 09:47:19
【问题描述】:
实际上,我正在使用 Kotlin 开发 Spring Boot v2 应用程序。我在版本 9 中使用 JDK。
添加依赖 spring-boot-starter-data-jpa 后,我收到 ClassNotFound 错误:
原因:org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class] 中定义名称为“entityManagerFactory”的 bean 创建错误:调用 init方法失败;嵌套异常是 java.lang.NoClassDefFoundError: javax/transaction/SystemException
我找到了一些针对该问题的文章,并在 /src/main/kotlin 下添加了 module-info.java 并包含以下内容:
module de.sample.backend {
// requires java.xml.bind;
requires javax.transaction.api;
// requires validation.api;
requires hibernate.jpa;
// requires hibernate.validator;
requires spring.beans;
requires spring.core;
requires spring.context;
requires spring.tx;
requires spring.web;
requires spring.webmvc;
requires spring.data.commons;
requires spring.data.jpa;
requires spring.boot;
requires spring.boot.autoconfigure;
// requires cache.api;
}
但是我会得到一个Caused by: java.lang.ArrayIndexOutOfBoundsException: 32800
[ERROR] 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (默认编译)在项目 naehmeisterei-services 上:执行 目标的默认编译 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed: 32800 -> [帮助 1] org.apache.maven.lifecycle.LifecycleExecutionException: 失败 执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (默认编译)在项目 naehmeisterei-services 上:执行 目标的默认编译 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed: 32800 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) 在 org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) 在 org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309) 在 org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194) 在 org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107) 在 org.apache.maven.cli.MavenCli.execute (MavenCli.java:955) 在 org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) 在 org.apache.maven.cli.MavenCli.main (MavenCli.java:194) 在 jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) 在 jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke (Method.java:564) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (启动器.java:289) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) 在 org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) 在 org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) 引起: org.apache.maven.plugin.PluginExecutionException:执行 目标的默认编译 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed: 32800
这是我完整的 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>de.sample.backend</groupId>
<artifactId>sample-services</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sample-services</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.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>-->
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<maven.compiler.release>9</maven.compiler.release>
<kotlin.version>1.2.20</kotlin.version>
</properties>
<dependencies>
<!-- Camunda - Spring Boot -->
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
<version>2.3.0</version>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://jaxenter.de/spring-boot-2-actuator-2-0-68749 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Kotlin -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Persistence / Database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<!-- Firebase -->
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>5.9.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
<jdkToolchain>
<version>9</version>
</jdkToolchain>
</configuration>
</plugin>
</plugins>
</build>
</project>
我实际上不知道如何解决这个问题。在另一台装有 JDK 8 的计算机上,它编译得很好。
有人可以帮忙吗?
谢谢!
更新
我使用 spring initialzr 创建了一个新的 spring-boot 项目: https://github.com/Chris81T/spring-boot-jdk9-kotlin-demo
如果不进行任何更改,我将得到相同的错误。也许有人可以寻找它来让它工作。那会很好:-)
【问题讨论】:
标签: hibernate maven spring-boot kotlin java-9