2012-12-18 255 views
0

当我尝试执行JUNIT测试用例时出现以下错误。 如果有人能帮助我,这将是非常有帮助的。运行JUNIT测试用例时出错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonValuesBackingBean' defined in class path resource [resources/ffms-storevisit-spring.xml]: Cannot resolve reference to bean 'cycleBackingBean' while setting bean property 'cycleBackingBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cycleBackingBean' defined in class path resource [resources/ffms-storevisit-spring.xml]: Cannot resolve reference to bean 'cycleManager' while setting bean property 'cycleManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cycleManager' defined in class path resource [resources/ffms-storevisit-spring.xml]: Cannot resolve reference to bean 'cycleBO' while setting bean property 'cycleBO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cycleBO' defined in class path resource [resources/ffms-storevisit-spring.xml]: Cannot resolve reference to bean 'cycleDAO' while setting bean property 'cycleDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cycleDAO' defined in class path resource [resources/ffms-storevisit-spring.xml]: Cannot resolve reference to bean 'sqlMapClient' while setting bean property 'sqlMapClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in class path resource [resources/ffms-common-spring.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient; 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) 
     at com.newsamerica.BaseTestCase.oneTimeSetUp(BaseTestCase.java:150) 
     at com.newsamerica.BaseTestCase.setUp(BaseTestCase.java:90) 
     at com.newsamerica.integration.dao.ffms.fcoperations.SelectiveRaiDAOTest.setUp(SelectiveRaiDAOTest.java:651) 
     at junit.framework.TestCase.runBare(TestCase.java:128) 
     at junit.framework.TestResult$1.protect(TestResult.java:106) 
     at junit.framework.TestResult.runProtected(TestResult.java:124) 
     at junit.framework.TestResult.run(TestResult.java:109) 
     at junit.framework.TestCase.run(TestCase.java:120) 
     at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) 
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

其中我尝试运行的代码是,

import java.util.ArrayList; 
import java.util.LinkedList; 
import java.util.List; 
import java.util.Map; 
import com.newsamerica.integration.dao.ffms.dispatchboard.DispatchBoardDAO; 
import com.newsamerica.value.ffms.fcoperations.EnableRAICodeValue; 
import com.newsamerica.value.ffms.fcoperations.SearchRequestLiteValue; 
import com.newsamerica.value.ffms.fcoperations.SearchRequestValue; 
import junit.framework.*; 
import com.newsamerica.BaseTestCase; 

public class SelectiveRaiDAOTest extends BaseTestCase { 
    SelectiveRaiDAO fixture = new SelectiveRaiDAO(); 
public SelectiveRaiDAOTest(){} 
    public void testCheckValidJobChain_1() 
     throws Exception { 
     Map<Object, Object> map = getMethodMap(this,"testCheckValidJobChain_1"); 
     EnableRAICodeValue enableValue = new EnableRAICodeValue(); 
     enableValue.setJobId((String)map.get("JobId")); 
     enableValue.setChainId((String)map.get("ChainId")); 
     enableValue.setWaveNumber((int) Double.parseDouble((String)map.get("WaveNumber"))); 
     boolean result = fixture.checkValidJobChain(enableValue); 
     assertTrue(result); 
     } 
protected void setUp() 
     throws Exception { 
     super.setUp(); 
     fixture = (SelectiveRaiDAO) getContext().getBean(
     "selectiveRaiDAO"); 
     } 
protected void tearDown() 
     throws Exception { 
     super.tearDown(); 
     } 
    public static void main(String[] args) { 
     if (args.length == 0) { 
      junit.textui.TestRunner.run(SelectiveRaiDAOTest.class); 
     } else { 
      TestSuite suite = new TestSuite("Selected tests"); 
      for (int i = 0; i < args.length; i++) { 
       TestCase test = new SelectiveRaiDAOTest(); 
       test.setName(args[i]); 
       suite.addTest(test); 
      } 
      junit.textui.TestRunner.run(suite); 
     } 
    } 

    @Override 
    protected String getPropertyFileName() { 
     return null; 
    } 
} 

在设置中的getContext.getBean方法存在下面的类(其是为弹簧注射)

 import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Collection; 
import java.util.Map; 
import java.util.ResourceBundle; 

import javax.faces.FactoryFinder; 
import javax.faces.application.ApplicationFactory; 
import javax.faces.component.UIViewRoot; 
import javax.faces.lifecycle.LifecycleFactory; 
import javax.faces.render.RenderKitFactory; 
import javax.sql.DataSource; 
import junit.framework.TestCase; 

import org.apache.commons.dbcp.BasicDataSource; 
import org.apache.shale.test.mock.MockApplication; 
import org.apache.shale.test.mock.MockExternalContext; 
import org.apache.shale.test.mock.MockFacesContext; 
import org.apache.shale.test.mock.MockFacesContextFactory; 
import org.apache.shale.test.mock.MockHttpServletRequest; 
import org.apache.shale.test.mock.MockHttpServletResponse; 
import org.apache.shale.test.mock.MockHttpSession; 
import org.apache.shale.test.mock.MockLifecycle; 
import org.apache.shale.test.mock.MockLifecycleFactory; 
import org.apache.shale.test.mock.MockRenderKit; 
import org.apache.shale.test.mock.MockServletConfig; 
import org.springframework.beans.factory.support.BeanDefinitionRegistry; 
import org.springframework.core.io.FileSystemResourceLoader; 
import org.springframework.mock.web.MockServletContext; 
import org.springframework.web.context.support.XmlWebApplicationContext; 
/* 
* Base spring test class 
*/ 
public abstract class BaseTestCase extends TestCase { 

    public static final String DATA_SOURCE = "com.newsamerica.DataSource"; 

    private static XmlWebApplicationContext context = null; 

    public static InputStream excelFile; 
    public static Collection<Object[]> spreadsheetData; 
    public static SpreadsheetData sheet; 
    public static Map<Object ,Object> paramMap; 
    //private static ShaleMockObjects shaleMockObjects; 
     public static MockApplication   application = null; 
     public static MockServletConfig  config = null; 
     public static MockExternalContext  externalContext = null; 
     public static MockFacesContext  facesContext = null; 
     public static MockFacesContextFactory facesContextFactory = null; 
     public static MockLifecycle   lifecycle = null; 
     public static MockLifecycleFactory lifecycleFactory = null; 
     public static MockRenderKit   renderKit = null; 
     public static MockHttpServletRequest request = null; 
     public static MockHttpServletResponse response = null; 
     public static MockServletContext  servletContext = null; 
     public static MockHttpSession   session = null; 


     public void loadTestSpreadsheet() throws IOException { 

        sheet=new SpreadsheetData(excelFile,null);   

       // System.out.println("k3"); 

       } 


     public DataSource getDataSource() { 
       BasicDataSource realDataSource = new BasicDataSource(); 
       realDataSource.setDriverClassName(getPropertyValue("driverClassName")); 
       realDataSource.setUrl(getPropertyValue("url")); 
       realDataSource.setUsername(getPropertyValue("username")); 
       realDataSource.setPassword(getPropertyValue("password")); 
       return realDataSource; 
      } 

    protected void setUp() throws Exception { 
     try { 


      if (context == null) { 
       super.setUp(); 
       oneTimeSetUp(); 
      } 
     } catch (Exception ex) { 
      //System.out.println(ex.getStackTrace()); 
     } 
    } 

    /* 
    * Setup the testing environment. 
    */ 
    protected void oneTimeSetUp() throws Exception { 
     try { 
      //System.out.println(excelFile); 
      excelFile = new FileInputStream(new File("D:/sure/workspace/NAPI/xxnapi/napi_war/config/resources/n/TestData-spreadsheet.xls")); 
      //System.out.println(excelFile); 
      sheet=new SpreadsheetData(excelFile); 
      //loadTestSpreadsheet(); 
     // spreadsheetData = sheet.getData(); 
       // paramMap=sheet.getMap(); 
       //System.out.println(paramMap); 
      if (context == null) { 
       String[] configFiles = new String[] { 


         "classpath:resources/jndiDataSource.xml", 
         "classpath:resources/ffms-common-spring.xml", 
         "classpath:resources/ffms-storevisit-spring.xml", 
         //"classpath:resources/ffms-cancelorders-faces.xml", 
         "classpath:resources/ffms-dispatchboard-spring.xml", 
         "classpath:resources/ffms-orgstructure-spring.xml", 
         "classpath:resources/ffms-emplookup-spring.xml", 
         "classpath:resources/ffms-exceptions-spring.xml", 
         "classpath:resources/ffms-fcoperations-spring.xml", 
         "classpath:resources/ffms-inventory-spring.xml", 
         "classpath:resources/ffms-jobinformation-spring.xml", 
         "classpath:resources/ffms-jobwavelookup-spring.xml", 
         "classpath:resources/ffms-loginhomepage-spring.xml", 
         "classpath:resources/ffms-manageuser-spring.xml", 
         "classpath:resources/ffms-masterstorelist-spring.xml", 
         "classpath:resources/ffms-messaging-spring.xml", 
         "classpath:resources/ffms-orgstructure-spring.xml", 
         "classpath:resources/ffms-orgstructureadmin-spring.xml", 
         "classpath:resources/ffms-shippinglocation-spring.xml", 
         "classpath:resources/ffms-storelist-spring.xml", 
         "classpath:resources/ffms-storelistassignment-spring.xml", 

         "classpath:resources/ffms-storevisitadmin-spring.xml", 
         "classpath:resources/ffms-survey-spring.xml", 
         "classpath:resources/ffms-tande-spring.xml", 
         "classpath:resources/ffms-tandemain-spring.xml" 
       }; 

       MockServletContext sctx = new MockServletContext(""); 
       context = new XmlWebApplicationContext(); 

       context.setServletContext(sctx); 

       context.setConfigLocations(configFiles); 

       context.setAllowBeanDefinitionOverriding(true); 
       context.refresh(); 
       BeanDefinitionRegistry factory = 
          (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory(); 
       factory.removeBeanDefinition("dataSource"); 
      // context.getBeanFactory().setAllowBeanDefinitionOverriding() 
       context.getBeanFactory().registerSingleton("dataSource",getDataSource()); 
       context.refresh(); 

       // Set up Servlet API Objects 
       // servletContext = new MockServletContext(); 
       // config = new MockServletConfig(servletContext); 
       session = new MockHttpSession(); 
       session.setServletContext(sctx); 
       request = new MockHttpServletRequest(session); 
       session.setId("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXERTXCDFBGFHDHFGDSDFDASSGGGGGG"); 
       request.setServletContext(sctx); 
       response = new MockHttpServletResponse(); 

       // Set up JSF API Objects 
       FactoryFinder.releaseFactories(); 
       FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, 
       "org.apache.shale.test.mock.MockApplicationFactory"); 
       FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, 
       "org.apache.shale.test.mock.MockFacesContextFactory"); 
       FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, 
       "org.apache.shale.test.mock.MockLifecycleFactory"); 
       FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, 
       "org.apache.shale.test.mock.MockRenderKitFactory"); 

       externalContext = 
        new MockExternalContext(sctx, request, response); 
       lifecycleFactory = (MockLifecycleFactory) 
       FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); 
       lifecycle = (MockLifecycle) 
       lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); 
       facesContextFactory = (MockFacesContextFactory) 
       FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); 
       facesContext = (MockFacesContext) 
       facesContextFactory.getFacesContext(sctx, 
         request, 
         response, 
         lifecycle); 
       externalContext = (MockExternalContext) facesContext.getExternalContext(); 
       UIViewRoot root = new UIViewRoot(); 
       root.setViewId("/viewId"); 
       root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT); 
       facesContext.setViewRoot(root); 
       ApplicationFactory applicationFactory = (ApplicationFactory) 
       FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); 
       application = new MockApplication(); 
       applicationFactory.setApplication(application); 
       facesContext.setApplication(application); 
       RenderKitFactory renderKitFactory = (RenderKitFactory) 
       FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); 
       renderKit = new MockRenderKit(); 
       renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit); 
      } 
     } catch (Exception ex) { 
      ex.printStackTrace(); 
      //System.out.println(ex.getStackTrace()); 
     } 
    } 

    public Map<Object, Object> getParamMap() { 
     return paramMap; 
    } 


    public Map<Object, Object> getMethodMap(String methodName) { 
     //System.out.println(methodName+"method name"); 
     // System.out.println(paramMap); 
      return (Map<Object, Object>) paramMap.get(methodName); 
    } 

     public Map<Object, Object> getMethodMap(Object obj,String methodName) { 
      //System.out.println(methodName+"method name"); 
      //System.out.println(obj.getClass().getName()); 
       return (Map<Object, Object>) sheet.getMap(obj.getClass().getName()).get(methodName); 
     } 

    public void setParamMap(Map<Object, Object> paramMap) { 
     this.paramMap = paramMap; 
    } 
    protected void tearDown() throws Exception { 
      //context.destroy(); 
      //context = null; 
      //super.tearDown(); 
     } 
    public String getPropertyValue(String propertyName) { 
     ResourceBundle testData = ResourceBundle 
       .getBundle(DATA_SOURCE); 
     return testData.getString(propertyName); 
    } 

    /** 
    * Gets the Properties file name. 
    * 
    * @return the Properties file name 
    */ 
    protected abstract String getPropertyFileName(); 

    /** 
    * @return the context 
    */ 
    public XmlWebApplicationContext getContext() { 
     return context; 
    } 

    /** 
    * @param context 
    *   the ctx to set 
    */ 
    public void setContext(XmlWebApplicationContext context) { 
     this.context = context; 
    } 

} 

热切期待回复。提前致谢。

+0

你需要做你的研究,并与你的问题更简洁。 –

+2

有点太多的代码,尝试减少到​​[SSCCE](http://sscce.org)。无论如何,你的线索是'调用init方法失败;嵌套异常是java.lang.NoSuchMethodError:com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(Ljava/io/InputStream; Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;' - 你的类路径中有两个版本的ibatis-sqlmap吗? –

+0

感谢您的答复Bystrup.There在我的课程路径只有一个版本的ibatis-sqlmap。忍受我,编程新手 – suresh

回答

1

如您所说,您的CLASSPATH中有ibatis-sqlmap jar。然后尝试打开它(它是zip文件)并检查是否有com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.class文件。

如果它不存在,那么这意味着你的jar损坏或被修改。如果它在那里,那么你的CLASSPATH是错误的。

相关问题