2017-03-02 64 views
1

我想測試我的課:無法加載TestContextBootstrapper [空]

@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的「值」屬性或使缺省引導程序類可用。

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 /郎/反映/ AnnotatedElement中; Ljava /郎/類;)Ljava/util的/設定; 在org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:150) 在org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126) ...... 23多個

+0

面對同樣的問題,你有任何解決方案? –

+0

沒有。我沒有解決方案。 – user

+0

此問題已經在這裏解答[http://stackoverflow.com/questions/28013452/could-not-load-testcontextbootstrapper-spring-unit-testing](http://stackoverflow.com/questions/28013452/could-not -load-testcontextbootstrapper - 彈簧 - 單元測試) – Thirumal

回答

1

我有類似的問題。 pom.xml文件中的依賴關係存在問題(如果您使用的是Maven)。可能有很多原因:版本衝突或衝突兩次聲明相同的依賴關係:在當前的pom.xml中,也在父pom.xml中,如使用不同版本。