【发布时间】:2020-11-18 20:54:21
【问题描述】:
尝试在 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)
我使用 ItelliJ 作为 IDE。
【问题讨论】:
-
能否请您添加 pom.xml 或 build.gradle 详细信息?
-
这样的错误通常来自于你正在混合来自不同版本的框架的 jars/modules,在这种情况下是 Spring。
-
是的,我知道。但不确定我在混合什么。是一个大项目,有很多依赖。
标签: java spring spring-boot maven junit