英文:
SpringFramework JUnit MergedAnnotations java.lang.NoClassDefFoundError
问题
尝试在Java SpringBoot应用程序中运行一些单元测试。
我运行的单元测试代码如下:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {WebAppInitializer.class})
public class FilePropertyInjectionUnitTest {
@Value("${geckoDir}")
private String geckoDir;
@Test
public void whenFilePropertyProvided_thenProperlyInjected() {
assertEquals(geckoDir, "C:\\GeckoDriver\\geckodriver.exe");
}
}
我遇到了以下错误:
java.lang.NoClassDefFoundError: org/springframework/core/annotation/MergedAnnotations
at org.springframework.test.context.support.DynamicPropertiesContextCustomizerFactory.isAnnotated(DynamicPropertiesContextCustomizerFactory.java:53)
at org.springframework.core.MethodIntrospector.lambda$selectMethods$1(MethodIntrospector.java:97)
at org.springframework.core.MethodIntrospector.lambda$selectMethods$0(MethodIntrospector.java:74)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:410)
at org.springframework.core.MethodIntrospector.selectMethods(MethodIntrospector.java:72)
at org.springframework.core.MethodIntrospector.selectMethods(MethodIntrospector.java:96)
我使用的是IntelliJ作为IDE。
英文:
Try ro run some unit tests in a Java SpringBoot application.
The unit test I run is :
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {WebAppInitializer.class})
public class FilePropertyInjectionUnitTest {
@Value("${geckoDir}")
private String geckoDir;
@Test
public void whenFilePropertyProvided_thenProperlyInjected() {
assertEquals(geckoDir,"C:\\GeckoDriver\\geckodriver.exe");
}
}
And I got the following error:
java.lang.NoClassDefFoundError: org/springframework/core/annotation/MergedAnnotations
at org.springframework.test.context.support.DynamicPropertiesContextCustomizerFactory.isAnnotated(DynamicPropertiesContextCustomizerFactory.java:53)
at org.springframework.core.MethodIntrospector.lambda$selectMethods$1(MethodIntrospector.java:97)
at org.springframework.core.MethodIntrospector.lambda$selectMethods$0(MethodIntrospector.java:74)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:410)
at org.springframework.core.MethodIntrospector.selectMethods(MethodIntrospector.java:72)
at org.springframework.core.MethodIntrospector.selectMethods(MethodIntrospector.java:96)
I am using ItelliJ as IDE .
答案1
得分: 1
我终于弄清楚了这个问题。我不得不将spring-test依赖项升级到版本5.2.8:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.8.RELEASE</version>
<scope>test</scope>
</dependency>
我真的在这个问题上走了很深。
英文:
I finally figure this one out.I had to upgrade spring-test dependency to version 5.2.8:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.8.RELEASE</version>
<scope>test</scope>
</dependency>
I really went down the rabitt hole with this one
答案2
得分: 0
以下是我的POM的一部分。我不知道哪些JAR包发生了冲突。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
</dependencies>
英文:
Below is part of my POM. I don't know what jars are clashing.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论