第一种:

@ContextConfiguration(locations = {"classpath*:/spring-core.xml"})
public class UserMapperTest extends AbstractJUnit4SpringContextTests {@Resourceprivate UserMapper userMapper;@Testpublic void testQueryAllUser () {User user = userMapper.queryById("1");System.out.println(user.getName());}
}

第二种:

public class UserMapperTest2 {private UserMapper userMapper;@Beforepublic void init(){ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath*:/spring/applicationContext.xml");  userMapper = (UserMapper)ctx.getBean("userMapper");}public UserMapper getUserMapper() {return userMapper;}public void setUserMapper(UserMapper userMapper) {this.userMapper = userMapper;}}

UserMapper需要加注解:

/*** 用户信息数据持久化操作接口*/
@Repository
public interface UserMapper extends BaseMapper<User>

IT技术和行业交流群 417691667

转载于:https://www.cnblogs.com/sun-rain/p/5766782.html

Junit测试 - Spring的配置相关推荐

  1. 原始Junit测试Spring的问题

    在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml" ...

  2. junit 测试 dao_JUnit测试Spring Service和DAO(带有内存数据库)

    junit 测试 dao 这篇文章描述了如何为Spring Web Application的Services和DAO实现JUnit测试. 它建立在Spring MVC-Service-DAO-Pers ...

  3. Spring MVC控制器JUnit测试

    JUnit测试Spring MVC控制器并非易事 . 但是最近,一个新项目 (即将在Spring推出)提供了新工具来简化此工作. 这篇文章说明了如何通过JUnit测试来测试一个简单的控制器. 该代码是 ...

  4. junit测试spring_使用Spring JUnit规则进行参数化集成测试

    junit测试spring Spring 4.2附带了全新的JUnit规则: SpringClassRule和SpringMethodRule . 使用JUnit规则的主要优点是让开发人员摆脱Spri ...

  5. logback property 默认值_看完这篇文章还不会给spring boot配置logback,请你吃瓜

    每一个成功人士的背后,必定曾经做出过勇敢而又孤独的决定. 放弃不难,但坚持很酷~ 一.logback日志框架 logback 是一个开源的日志组件,由三个部分组成:logback-core,logba ...

  6. junit 测试mvc_Spring MVC控制器JUnit测试

    junit 测试mvc JUnit测试Spring MVC控制器并非易事 . 但是最近,一个新项目 (即将在Spring推出)提供了新的工具来简化此工作. 这篇文章说明了如何通过JUnit测试来测试一 ...

  7. Spring学习笔记(二)——Spring相关配置属性注入Junit整合

    一.Spring的相关配置 1.1 Bean元素 class属性:被管理对象的完整类名 name属性:给Bean起个名字,能重复,能使用特殊字符.后来属性 id属性:给Bean起个名字,不能重复,不能 ...

  8. Spring(二)——Junit测试工具、属性的注入方式、注解

    文章目录 1. Junit 测试工具 2. getBean的五种用法 3. 属性的注入方式 4. bean的生存范围和加载策略 5. 自定义属性的注入方式 6. Spring中各类注解的作用 1. J ...

  9. 基础概念总结(spring security、Quartz、JUnit测试)

    1.Spring Security 的大体框架和原理 (1)在web.xml中配置过滤器,这样就可以控制这个项目的每个请求.  (2)在applicationContext.xml配置,其中http标 ...

最新文章

  1. 软件测试面试的linux基础知识,linux基础面试题
  2. SDwebimage使用原理(转载)
  3. C 库函数 int fprintf(FILE *stream, const char *format, ...) 发送格式化输出到流 stream 中
  4. java程序设计 第2版 唐大仕_《Java程序设计(第2版)》唐大仕 源代码
  5. java 假设当前时间_Java如何比较当前时间是否在两个时间范围内
  6. 傅里叶变换的初级理解一
  7. 漳州职业技术学院计算机学费多少钱,漳州职业技术学院单招2021年学费多少
  8. 利用大数据构建智能交通
  9. 数字电路基础知识——锁存器与触发器在Verilog中使用问题
  10. python123平台怎么上课_国内优秀的Python教学平台推荐-python123.io
  11. linux centos7 录屏,centos7在线安装视频录制软件
  12. 千万级 PV是什么意思?
  13. 电精(1-2代)全介绍攻略
  14. 如何自动执行Excel的多次替换--Excel批量替换工具
  15. AD域部署软件自动下发
  16. python:引入requests报错“could not be resolved” 解决方案
  17. 蠕动泵的流量如何计算?
  18. Spark Executor heartbeat timed out
  19. MATLAB水果品质自动分级系统
  20. K-means 之国足小例子

热门文章

  1. 在ubuntu 中如何保存及播放DVD
  2. BP神经网络 语音信号分类
  3. 堆排序(C\C++)
  4. centos 安装指定版本gc_番外篇 (1) Docker 安装
  5. 【HDU5306】【DTOJ2481】Gorgeous Sequence【线段树】
  6. 采集文件到kafka
  7. 2019-05-23 IRIS嗅探器;用IRIS嗅探数据;
  8. Catalyst3560密码破解
  9. webStorm 注册码
  10. Idea根据表自动生成实体