zoukankan      html  css  js  c++  java
  • 使用mybatis时 异常笔记

    在Test中写测试代码时,与直接启动项目不同,不会启动spring,需要手动去加载spring,具体例子如下:

    首先在引入spring等依赖的同时要引入junit与spring-test这两个测试工具。

    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <version>${spring.version}</version>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
    package com.dzh.Test;
    import com.dzh.dao.PersonMapper;
    import com.dzh.entity.Person;
    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;
    
    /**
     * @Description TODO
     * @ClassName TestSpring
     * @Author DingZuoHeng
     * @Date 2019年3月4日
     * @Version 1.0
     **/
    //告诉spring容器运行在虚拟机中
    @RunWith(SpringJUnit4ClassRunner.class)
    //配置文件的位置
    //若当前配置文件名=当前测试类名-context.xml 就可以在当前目录中查找@ContextConfiguration()
    @ContextConfiguration("classpath:spring-mvc.xml")
    public class TestSpring {
        @Autowired
        private PersonMapper personMapper;
        @Test
        public  void test01(){
            System.out.println("13256");
            Person test = personMapper.test();
            System.out.println(test);
        }
    }
    
  • 相关阅读:
    输入法或搜索类软件评价
    Money-去哪了每日站立会议
    Money去哪了- 每日站立会议
    Money去哪了- 每日站立会议
    课下作业-典型用户描述,描绘用户场景
    Money去哪了-每日站立会议
    Money去哪了- 每日站立会议
    Money-去哪了每日站立会议
    Money去哪了- 每日站立会议
    Money-去哪了每日站立会议
  • 原文地址:https://www.cnblogs.com/dingzuoheng/p/12805066.html
Copyright © 2011-2022 走看看