今天使用Spring 和mybatis框架编写项目,写了个测试方法方便测试,之前因为一直报空指针,注入不了,所以简单记录一下,方便以后使用
root.xml
测试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;