私はこのようなJUnitテストを行っています。これは、より大きなアプリケーションの一部です。Spring Root Controllerを盗む他のJUnitテストを中止するにはどうしたらいいですか?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = { MyTestConfig.class })
public class MyHandlerInterceptorTest {
@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;
@Test
public void myTest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET",
"/myrequest");
HandlerExecutionChain handlerExecutionChain = requestMappingHandlerMapping.getHandler(request);
}
}
テストを単独で実行すると、正常に動作します。
私は他のテストのスイートの一部としてそれを実行 - 私が起こっているように見える何
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.MyHandlerInterceptorTest ': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping com.MyHandlerInterceptorTest.requestMappingHandlerMapping; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextException: Cannot reinitialize with different application context: current one is [Root WebApplicationContext: startup date [XXX 2016]; root of context hierarchy], passed-in one is [[email protected]60457f: startup date [XXX 2016]; root of context hierarchy]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:376)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:313)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
....
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping com.MyHandlerInterceptorTest.requestMappingHandlerMapping; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextException: Cannot reinitialize with different application context: current one is [Root WebApplicationContext: startup date [XXX 2016]; root of context hierarchy], passed-in one is [[email protected]60457f: startup date [Fri Mar 18 11:01:19 EST 2016]; root of context hierarchy]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
エラーを取得するには、私のテストコンテキストが他のテストによって盗まれていることです。私はこれがいつ発生するのかを特定し、それを止める方法、または少なくともそれを回避する方法を知りたい。
私の質問は:Spring Root Controllerを盗む他のJUnitテストを中止するにはどうしたらいいですか?
ブリリアント提案。 http://www.jroller.com/arondight/entry/mocking_a_webapplicationcontext_in_orderを行うもっと簡単な方法です。残念なことに、これらの両方ともエラーが発生します。http://stackoverflow.com/questions/10013288/another-unnamed-cachemanager-already-exists-in-theame-vm-ehcache-2-5 私は何を書きますか?私はそうしました - 基本的にこれはhttp://stackoverflow.com/questions/7239786/how-to-invoke-the-same-maven-build-twice-in-one-call – hawkeye