日期:2014-05-18  浏览次数:20885 次

使用junit测试springMVC项目出现错
测试类:

    package cn.com.qzinfo.test.example;  
      
    import org.junit.Test;  
    import org.junit.runner.RunWith;  
    import org.springframework.beans.factory.annotation.Autowired;  
    import org.springframework.context.ApplicationContext;  
    import org.springframework.context.support.ClassPathXmlApplicationContext;  
    import org.springframework.test.context.ContextConfiguration;  
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;  
      
    import cn.com.qzinfo.example.dao.ExampleDao;  
    import cn.com.qzinfo.example.model.Example;  
      
    @RunWith(SpringJUnit4ClassRunner.class)    
    @ContextConfiguration(locations={"classpath:applicationContext.xml"})      
    public class ExampleDaoTest{  
      
        @Autowired  
        private ExampleDao exampleDao;  
          
        @Test  
        public void test() {  
            Example example =new Example();  
            example.setOperatorId(111);  
            example.setIntRev1(111);  
            exampleDao.insert(example);  
        }  
    }  


spring配置:

    <?xml version="1.0" encoding="UTF-8"?>  
    <beans xmlns="http://www.springframework.org/schema/beans"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"  
        xmlns:context="http://www.springframework.org/schema/context"  
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
        xsi:schemaLocation="          
            http://www.springframework.org/schema/beans           
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd