spring-test跟junit结合单元测试获取ApplicationContext实例的方法
步骤
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;
}
}
spring-test跟junit结合单元测试获取ApplicationContext实例的方法的更多相关文章
- 【转】SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
转自:http://www.coderli.com/junit-spring-test-applicationcontext JUnit单元测试用例中使用Spring框架,直接方式如下. @RunWi ...
- SpringTest框架JUnit单元测试用例获取ApplicationContext实例的方法
步骤 1.继承AbstractJUnit4SpringContextTests 2.引入ApplicationContext 示例代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- spring获取ApplicationContext对象的方法——ApplicationContextAware
一. 引言 工作之余,在看一下当年学的spring时,感觉我们以前都是通过get~ set~方法去取spring的Ioc取bean,今天就想能不能换种模型呢?因为我们在整合s2sh时,也许有那么一天就 ...
- 获取applicationContext对象的方法
方法一:在初始化时保存ApplicationContext对象 代码: ApplicationContext ac = new FileSystemXmlApplicationContext(&quo ...
- Spring容器中获取bean实例的方法
// 得到上下文环境 WebApplicationContext webContext = ContextLoader .getCurrentWebApplicationContext(); // 使 ...
- spring junit 做单元测试,报 Failed to load ApplicationContext 错误
spring junit 做单元测试,报 Failed to load ApplicationContext 错误. 查找了好一会,最后发现.@ContextConfiguration(locatio ...
- 使用Spring配合Junit进行单元测试的总结
最近公司的项目和自己的项目中都用到了spring集成junit进行单元测试,总结一下几种基本的用法: 1.直接对spring中注入的bean进行测试(以DAO为例): 在测试类上添加@RunWith注 ...
- Spring获取ApplicationContext
在Spring+Struts+Hibernate中,有时需要使用到Spring上下文.项目启动时,会自动根据applicationContext配置文件初始化上下文,可以使用ApplicationCo ...
- Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式
转自:http://chinazhaokeke.blog.163.com/blog/static/109409055201092811354236 Spring获取ApplicationContex ...
随机推荐
- ADB命令指令控制Android系统的WIFI连接开启/关闭状态
Android系统的usb调试已开启,连接电脑(有ADB环境) 1.在cmd中,进入shell指令模式 adb shell 2.进入ROOT指令模式 su 3. 打开WIFI指令 svc wifi e ...
- 前端知识点回顾——Javascript篇(一)
DOM特殊元素获取 document.documentElement //HTML标签 document.head //head标签 document.title //title标签 document ...
- vscode在软件内部查看html渲染效果的插件
使用方法: Usage press 'F1' and type "Show Live Server Preview" F1,然后输入Show Live Server Preview ...
- NaN情况下无法比较大小
<pre name="code" class="java">package nan; /** * NaN情况下无法比较大小 * @author ro ...
- 在CentOS7阿里云服务器部署ThinkPHP5,并配置phpstrom实现同步开发(微信小程序及管理员后端)
小程序和后端同步开发 1.服务器安装tp5框架: 方法很多比如:github.linux命令直接手动下.composer 都可以,方法很多,百度一下,不再累述 2.这时你会发现怎么都访问出现不了这个令 ...
- hibernate关联映射之一对多&多对一
package loaderman.b_one2Many; import java.util.HashSet; import java.util.Set; public class Dept { pr ...
- RDD的cache 与 checkpoint 的区别
问题:cache 与 checkpoint 的区别? 关于这个问题,Tathagata Das 有一段回答: There is a significant difference between cac ...
- AC自动机--summer-work之我连模板题都做不出
这章对现在的我来说有点难,要是不写点东西,三天后怕是就一无所有了. 但写这个没有营养的blog的目的真的不是做题或提升,只是学习学习代码和理解一些概念. 现在对AC自动机的理解还十分浅薄,这里先贴上目 ...
- document.documentElement.clientHeight 和 document.body.clientHeight
document.documentElement.clientHeight 和 document.body.clientHeight 介绍 在进行一些网页效果处理的时候,经常碰到document.do ...
- uni-app相关
uni-app 中以下组件的高度是固定的,不可修改: 导航栏高度固定为 44pxtabBar 高度固定为 56px 状态栏比较特殊,是一个变量 .status_bar{ height: var(--s ...