英文:
JDK14-SpringBoot-Maven-Cassandra: "Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7" exception only with Cassandra dependency
问题
在我开始之前:是的,Stack Overflow 上有类似的问题,但是没有一个与我的环境和设置完全相同的(大多数问题与 Gradle 构建有关,很多甚至与 Spring 无关)。
此外,这让人困惑,因为只有在尝试使用 Spring Boot 的 Cassandra 依赖时才会出现这个问题:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
但是,每当我尝试启动应用程序时,都会每次遇到以下异常:
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
我不明白为什么会出现这个问题,因为我甚至没有使用 Gradle!我使用的是和我所有的 Spring Boot 项目一样的 Maven,但是只有在添加了 Spring Data Cassandra 依赖后才会出现这个问题。
我假设在 pom 文件中添加 org.codehaus.groovy
依赖会解决这个问题,但实际上并没有起作用!
正如标题所说,我在 MacOs Catalina 上安装了 JDK 14。在任何非 Cassandra 的 Spring Boot 项目中,我的 JDK 都能够正常工作。
是不是 spring-data-cassandra 需要另外的依赖?只能与 Gradle 一起使用吗?
如果有人能够帮助我解决这个问题,我将不胜感激。我真的不知道这可能是什么问题,网络上关于 Cassandra 支持的信息非常有限。
感谢阅读!
这是我的 POM 文件:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cassandra</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>example</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<!-- 其他依赖 -->
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.6</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<!-- 构建插件等配置 -->
</build>
</project>
这是完整的异常堆栈跟踪:
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:107)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.<init>(GroovyBeanDefinitionReader.java:150)
at org.springframework.boot.BeanDefinitionLoader.<init>(BeanDefinitionLoader.java:85)
at org.springframework.boot.SpringApplication.createBeanDefinitionLoader(SpringApplication.java:738)
at org.springframework.boot.SpringApplication.load(SpringApplication.java:681)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:392)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.cassandra.example.ExampleApplication.main(ExampleApplication.java:21)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
2020-10-25 14:00:14.948 ERROR 5918 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
英文:
Before I start: YES, there are similar questions in SO about this, but not a single one have the same environment and settings as me (Most of the issues were related to gradle builds and a lot weren't even Spring related)
Furthermore, this is confusing because this only occurs when trying to use the Spring Boot's Cassandra dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
But whenever i try to start the application, I'm running with the next exception every time!
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
I don't understand why this happens because I'm not even using Gradle! I'm using Maven as in any of my Spring Boot Projects but this problem only happens whenever I add the Spring Data Cassandra Dependency.
I assumed that adding the org.codehaus.groovy
dependency in the pom file would solve the problem, but still doesn't works!
As the title says, I have JDK 14 installed on MacOs Catalina. My JDK works as expected with any other dependency in any non-cassandra spring boot project.
Does spring-data-cassandra requires another dependency? Can only be used with Gradle?
I'd really appreciate if someone could give me a hand with this. I have no idea what this could be and Cassandra Support is very limited in the web.
Thanks for reading!
Here's my POM FILE:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cassandra</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>example</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.6</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And here's the full Stacktrace of the exception:
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:107)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.<init>(GroovyBeanDefinitionReader.java:150)
at org.springframework.boot.BeanDefinitionLoader.<init>(BeanDefinitionLoader.java:85)
at org.springframework.boot.SpringApplication.createBeanDefinitionLoader(SpringApplication.java:738)
at org.springframework.boot.SpringApplication.load(SpringApplication.java:681)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:392)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.cassandra.example.ExampleApplication.main(ExampleApplication.java:21)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
2020-10-25 14:00:14.948 ERROR 5918 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
答案1
得分: 6
看起来其中一个依赖项正在使用旧版本的Groovy。如果你使用以下命令检查依赖树:
mvn dependency:tree -Dincludes=org.codehaus.groovy
你可以看到需要它的依赖关系:
[INFO] com.example:demo:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-data-cassandra:jar:2.3.4.RELEASE:compile
[INFO] \- org.springframework.data:spring-data-cassandra:jar:3.0.4.RELEASE:compile
[INFO] \- com.datastax.oss:java-driver-core:jar:4.6.1:compile
[INFO] \- org.apache.tinkerpop:gremlin-driver:jar:3.4.5:compile
[INFO] +- org.codehaus.groovy:groovy:jar:indy:2.5.7:compile
[INFO] \- org.codehaus.groovy:groovy-json:jar:indy:2.5.7:compile
一个临时的解决方案是排除这些依赖项,然后添加新版本的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.5.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>2.5.13</version>
</dependency>
英文:
Looks like one of the dependencies is using old version of groovy. If you check the dependency tree using command :
mvn dependency:tree -Dincludes=org.codehaus.groovy
you can see the dependency that requries it :
[INFO] com.example:demo:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-data-cassandra:jar:2.3.4.RELEASE:compile
[INFO] \- org.springframework.data:spring-data-cassandra:jar:3.0.4.RELEASE:compile
[INFO] \- com.datastax.oss:java-driver-core:jar:4.6.1:compile
[INFO] \- org.apache.tinkerpop:gremlin-driver:jar:3.4.5:compile
[INFO] +- org.codehaus.groovy:groovy:jar:indy:2.5.7:compile
[INFO] \- org.codehaus.groovy:groovy-json:jar:indy:2.5.7:compile
A temporary solution would be to exclude those dependencies and add them with newer version :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.5.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>2.5.13</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论