Sprint + mybatis 编写测试

今天使用Spring 和mybatis框架编写项目,写了个测试方法方便测试,之前因为一直报空指针,注入不了,所以简单记录一下,方便以后使用

 

root.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">
    <import resource="classpath*:spring.xml"/>
    <import resource="classpath*:spring-mybatis.xml"/>
</beans>

 

测试RedisTest.java

package org.test;

import org.dao.GhksMapper;
import org.dao.KsdmdzMapper;
import org.dao.YgdmMapper;
import org.dao.YspbMapper;
import org.dao.YyghMapper;
import org.dao.ZxksMapper;
import org.junit.Before;
import org.junit.Test;
import org.service.UploadServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试
 */
public class RedisTest {

    @Autowired
    private YgdmMapper ygdmMapper;

    @Autowired
    private YspbMapper yspbMapper;

    @Autowired
    private GhksMapper ghksMapper;

    @Autowired
    private YyghMapper yyghMapper;

    @Autowired
    private KsdmdzMapper ksdmdzMapper;

    @Autowired
    private ZxksMapper zxksMapper;
    
    @Autowired
    private UploadServiceImpl uploadServiceImpl;

    @Before
    public void init(){
        ApplicationContext   context = new ClassPathXmlApplicationContext("classpath*:root.xml");//这里路径之前没有配对于是一直出错
        ygdmMapper = (YgdmMapper)context.getBean("ygdmMapper");
        yspbMapper = (YspbMapper)context.getBean("yspbMapper");
        ghksMapper = (GhksMapper)context.getBean("ghksMapper");
        yyghMapper = (YyghMapper)context.getBean("yyghMapper");
        ksdmdzMapper = (KsdmdzMapper)context.getBean("ksdmdzMapper");
        zxksMapper = (ZxksMapper)context.getBean("zxksMapper");
        uploadServiceImpl = (UploadServiceImpl)context.getBean("uploadServiceImpl");
    }
    
    @Test
    public void test() {
        //上传挂号科室代码
        uploadServiceImpl.getS201();
        //上传挂号医生代码
        uploadServiceImpl.getS202();
        //上传科室医生排班表
        uploadServiceImpl.getS203();
        //上传挂号医生停诊表
        uploadServiceImpl.getS204();
        //上传其他预约方式出退号记录
        uploadServiceImpl.getS205();
        //上传本平台预约的取号记录
        uploadServiceImpl.getS206();
        //上传排班预约数量记录
        uploadServiceImpl.getS208();
        //上传预约时间点记录
        uploadServiceImpl.getS301();
        //上传预约时间点停用记录
        uploadServiceImpl.getS302();
        uploadServiceImpl.getMzjcxx();
        uploadServiceImpl.getZyjcxx();
    }
    
}

 

OK;

 

posted @ 2017-01-19 11:48  耀仔  阅读(307)  评论(0编辑  收藏  举报