SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
步骤
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = { "/spring/applicationContext.xml" })public class SpringTest extends AbstractJUnit4SpringContextTests { @Autowired protected ApplicationContext ctx; public <T> T getBean(Class<T> type) { return applicationContext.getBean(type); } public Object getBean(String beanName) { return applicationContext.getBean(beanName); } protected ApplicationContext getContext() { return applicationContext; }} |
SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法的更多相关文章
- 【转】SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
转自:http://www.coderli.com/junit-spring-test-applicationcontext JUnit单元测试用例中使用Spring框架,直接方式如下. @RunWi ...
- spring-test跟junit结合单元测试获取ApplicationContext实例的方法
步骤 1.继承AbstractJUnit4SpringContextTests 2.引入ApplicationContext 示例代码:(可以根据name或者类型获取bean) import or ...
- spring获取ApplicationContext对象的方法——ApplicationContextAware
一. 引言 工作之余,在看一下当年学的spring时,感觉我们以前都是通过get~ set~方法去取spring的Ioc取bean,今天就想能不能换种模型呢?因为我们在整合s2sh时,也许有那么一天就 ...
- 获取applicationContext对象的方法
方法一:在初始化时保存ApplicationContext对象 代码: ApplicationContext ac = new FileSystemXmlApplicationContext(&quo ...
- spring 框架通过new Object()获取applicationContext 中的bean方案
工作中,需要手动创建一个对象,但用到了spring容器中对象的业务逻辑,这时候就要去通过获取容器中的对象.这时候,可以通过实例化一个实现了ApplicationContextAware接口的类获取sp ...
- 教你快速写出多线程Junit单元测试用例 - GroboUtils
摘自: http://mushiqianmeng.blog.51cto.com/3970029/897786/ 本文出自One Coder博客,转载请务必注明出处: http://www.coderl ...
- spring框架中由FactoryBean获取JedisCluster实例
spring配置文件: <bean id="jedisCluster" class="com.pingan.ela.structure.ex.JedisCluste ...
- Spring容器中获取bean实例的方法
// 得到上下文环境 WebApplicationContext webContext = ContextLoader .getCurrentWebApplicationContext(); // 使 ...
- 【spring框架】spring获取webapplicationcontext,applicationcontext几种方法详解--(转)
方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXmlApplicationContext(" ...
随机推荐
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A 思路: 贪心,每次要么选两个最大的,要么选三个,因为一个数(除了1)都可以拆成2和3相加,直到所有的数都相同就停止,这时就可以得到答案了; C: 二分+bfs,二分答案,然后bfs找出距离小于等于 ...
- Hoj2634 How to earn more?
How to earn more My Tags (Edit) Source : ww Time limit : 1 sec Memory limit : 64 M Submitted ...
- ef操作类
基于Hi博客的类库 20160811 using Model; using System; using System.Collections.Generic; using System.Data.En ...
- mvc5权限管理(简单登录):ActionFilterAttribute
效果图: 1.控制器 public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(User ...
- c#简要概括面向对象的三大特征
要去面试了,朋友给我出个问题: 一,封装: 我们可以把世界上任何一个东西都看作为一个对象,那么我们这里以人为例,一个人就肯定是一个对象了. 那么封装是什么呢?封装就是这个人要完成一件事情,他所需要的任 ...
- TP框架实现分页
TP框架自带分页的实现方法,所以使用这个分页方案,不用再重新造轮子 1,先看效果图 2,源码 /** * TODO 基础分页的相同代码封装,使前台的代码更少 * @param $m 模型,引用传递 * ...
- Broadmann area (wiki)
Source: https://en.wikipedia.org/wiki/Brodmann_area Lateral surface Medial serface Areas 3, 1 & ...
- 【MySql】C#数据库备份与还原
public static class SQLBackup { /// <summary> /// 执行Cmd命令 /// </summary> /// <param n ...
- JavaScript系列:正则表达式
function testExecResultType() { var txt = "mom and dad and baby"; var pattern = /mom (and ...
- eval解析JSON字符串的一个小问题
之前写过一篇 关于 JSON 的介绍文章,里面谈到了 JSON 的解析.我们都知道,高级浏览器可以用 JSON.parse() API 将一个 JSON 字符串解析成 JSON 数据,稍微欠妥点的做法 ...