如果是maven项目,pom中增加如下依赖:

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.1.1.RELEASE</version>
</dependency>

import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.fastjson.JSON;
import com.joey.model.InfoCfg;
import com.joey.model.UrUser;
import com.joey.service.InfoCfgServiceI;
import com.joey.service.UrUserServiceI;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring.xml", "classpath:spring-mybatis.xml" })
public class TestMybatis {

    //public ApplicationContext ac;
    private static final Logger logger = Logger.getLogger(TestMybatis.class);

    private InfoCfgServiceI infoService;
    private UrUserServiceI uruserService;

/*    @Before
    public void before(){
        ac=new ClassPathXmlApplicationContext(new String[]{"spring.xml","spring-mybatis.xml"});
        uruserService = (UrUserServiceI)ac.getBean("uruserService");
        infoService = (InfoCfgServiceI)ac.getBean("infoService");

    }*/
    
    @Test
    public void test1() {
        InfoCfg u = infoService.get****(2985l); //相关业务方法
        logger.info(JSON.toJSONStringWithDateFormat(u, "yyyy-MM-dd HH:mm:ss"));
    }
    
    @Test
    public void testUser() {
        UrUser u = uruserService.******(285l);  //相关业务方法
        //logger.info(JSON.toJSONStringWithDateFormat(u, "yyyy-MM-dd HH:mm:ss"));
        logger.info(u.getUserId()+",,,,"+u.getCompany());
    }

    public InfoCfgServiceI getInfoService() {
        return infoService;
    }

    @Autowired
    public void setInfoService(InfoCfgServiceI infoService) {
        this.infoService = infoService;
    }

    public UrUserServiceI getUruserService() {
        return uruserService;
    }

    @Autowired
    public void setUruserService(UrUserServiceI uruserService) {
        this.uruserService = uruserService;
    }
}

相关文章: