您好,我正在尝试在Spring中使用JUnit测试我的webservice。我写了这个测试:使用JUnit测试Spring Web服务时的错误4
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:META-INF/applicationContext.xml"})
@TransactionConfiguration
@Transactional
@SuppressWarnings("unused")
public class SiteTest {
@Mock
public IBusiness siteBusiness;
@Autowired
public ManageImpl managesiteI;
List<GeographicSite> sitesJson = null;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
siteApplicationImpl=new ManageSiteImpl(siteApplicationBusiness);
}
@Test
public void testSizeOfSIte() throws ExceptionApiV2 {
try {
when(managesiteI.geographicSitesAPIV2(Mockito.eq((Integer)10), Mockito.eq((Integer)0), Mockito.anyString(), Mockito.anyString(),
Mockito.eq("CI00002384"),Mockito.eq("CI00002394"), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(resultat);
} catch (Exception e) {
System.out.println("ERRO MOCKITO: "+e);
}
sitesJson=managesiteI.geographicSitesAPIV2(10, 0, "site.id", null, "CI00002384" , "CI00002394", null, null, null, null, null, null, null, null, null, null);
我已经加入applicationContext.xml中 添加的所有,我想我需要 依赖但它不能正常工作, 首先我得到的日志这样的错误:
log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog).
log4j:WARN Please initialize the log4j system properly.
我设法用一个静态方法来跳过它,但我一直这个错误:
Destroying singletons in org.s[email protected]7a95626d: defining beans [propertyConfigurer,getActor.proxyFactory,getActor,actorBusinessImpl,manageSiteSoapProxy,manageSiteSoapProxyFactory,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionInterceptor,transactionManager,transactionAttributes,autoProxyTransactionCreator,dataSource,siterefEntityManagerFactory,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0]; root of factory hierarchy
Caught exception while allowing TestExecutionListener [org.springframewor[email protected]8fb4c62] to prepare test instance [[email protected]]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157) ~[spring-test-3.1.0.RELEASE.jar:3.1.0.RELEASE]
我有这个引起的:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [META-INF/jpaDaoContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'siterefEntityManagerFactory' defined in class path resource [META-INF/jpaDaoContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/resource/spi/XATerminator
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) ~[spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
编辑
我有这个错误之前德最后一个:我不认为我有同样的问题,其他的问题;
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'siterefEntityManagerFactory' defined in class path resource [META-INF/jpaDaoContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/resource/spi/XATerminator
****编辑2 ***
加入javax.resource 的依赖后,我得到这个/
Bean 'siterefEntityManagerFactory' of type [class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Pre-instantiating singletons in org.s[email protected]72ee3d51: defining beans [propertyConfigurer,getActor.proxyFactory,getActor,.....]; root of factory hierarchy
FactoryBean threw exception from getObjectType, despite the contract saying that it should return null if the type of its object cannot be determined yet`
任何一个有什么想法?我错过了什么? ,如果你认为我应该详细的东西让我知道,谢谢你的回答和评论
无ü已编辑的问题,清除了这一点:) –
这是一个错误或警告?它应该在日志中。 – randominstanceOfLivingThing
你可以发布你的applicationContext.xml吗? – randominstanceOfLivingThing