我试着测试我的课程:
@Configuration
public class PluginConfig {
@Bean
public Supplier messageSupplier(){
return () -> "plugin";
}
@Repository
public interface CountryRepository extends JpaRepository<CountryEntity, Long> {}
我的测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfigurationde
public class PluginConfigTest {
@Autowired
private CountryRepository repository;
@Test
public void nullable() {
assertNotNull(repository);
}
我有一个例外:
java.lang.IllegalStateException:无法加载TestContextBootstrapper [null]。指定@ BootstrapWith&#39; s&#39; value&#39;属性或使默认的bootstrapper类可用。
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:143)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
引起:java.lang.NoSuchMethodError:org.springframework.core.annotation.AnnotatedElementUtils.findAllMergedAnnotations(Ljava / lang / reflect / AnnotatedElement; Ljava / lang / Class;)Ljava / util / Set; 在org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:150) 在org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126) ......还有23个
答案 0 :(得分:2)
我有类似的问题。 pom.xml文件中的依赖项存在问题(如果您使用的是Maven)。这可能有很多原因:版本冲突或冲突声明相同的依赖两次:在当前的pom.xml中以及在父pom.xml中,就像使用不同的版本一样。