2017-01-19 39 views
0

,當我在寫測試用例來我的春天文件我最終得到一個錯誤,我不能修復它。這裏有一些下面的代碼片段詢問我是否需要更多。無法加載我是新來的JUnit和Spring框架TextContextbootstapper JUnit的錯誤

的pom.xml

<!-- Spring framework --> 



<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-context</artifactId> 
<version>4.1.6.RELEASE</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test --> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-test</artifactId> 
<version>4.1.6.RELEASE</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-core</artifactId> 
<version>4.1.6.RELEASE</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-beans</artifactId> 
<version>4.1.6.RELEASE</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web --> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-web</artifactId> 
<version>4.1.6.RELEASE</version> 
</dependency> 

錯誤

java.lang.IllegalStateException: Could not load TestContextBootstrapper [class org.springframework.test.context.support.DefaultTestContextBootstrapper]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available. 
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:87) 
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:102) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:124) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:115) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source) 
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) 
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) 
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:26) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object; 
    at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:81) 
    ... 21 more 

JunitTestclass.java

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={ 
"file:src/main/resources/config/spring/beans/HibernateSessionFactory.xml", 
"file:src/main/resources/config/spring/beans/DataSourceTest.xml", 
"file:src/main/resources/com/dynaprice/customer/spring/CustomerBean.xml"}) 
public class RepricingBeanTest { 

@Autowired 
RepricingBean beanrep ;} 

謝謝你問我的y文件,如果你需要的話。

回答

0

也許這是一個版本衝突。你使用其他Spring包的更新版本(4.1.6.RELEASE)的舊版基礎Spring(2.5.6)。看看這個帖子:Could not load TestContextBootstrapper - Spring Unit testing

+0

沒有改變,甚至我改變舊版本到新的東西。 –

+0

您是否嘗試過使用乾淨的命令重新運行maven,例如'mvn clean test'?另一件事可能是你不必在你的依賴中包含junit,因爲它已經包含在spring-test中。你可以在發佈更改後發佈你的pom.xml文件嗎? – luke

+0

我在我的項目中重新測試了您的案例。我犯了一個小錯誤。你仍然需要junit依賴,但是當你將它添加到當前的pom.xml中時,pom.xml應該可以。我認爲問題出現在@ContextConfiguration(locations = {...})'。看起來你沒有正確地導入上下文,所以spring並沒有看到它。也許修改文件在某種程度上是錯誤的,或者這些文件中的配置有些不對。在我的應用我有上下文正確導入和測試工作正常,但是當我註釋掉'@ContextConfiguration(...)'我得到了同樣的錯誤,你這樣這樣,我認爲問題出在上述地方 – luke

相關問題