spring-junit的标注总结
如果在测试类的类名上面添加了注解
@ContextConfiguration("meta/springConfigured.xml")
如何在标注了@Test的方法里面获取上面xml文件中的配置?
package aoptest; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith; import aoptest.ShouldBeConfiguredBySpring; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextLoader;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /**
* @author Administrator
*
*/
@RunWith(SpringJUnit4ClassRunner.class)//必须有,如果去掉,下面的ctx就不能注入
@ContextConfiguration("/meta/springConfigured.xml")
public class TestAop { @Autowired
protected ApplicationContext ctx; @Test
public void aopTest(){
//第一种方法
//ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("meta/springConfigured.xml");
//ShouldBeConfiguredBySpring myObject = (ShouldBeConfiguredBySpring) context.getBean("configuredBean");
//System.out.println(myObject.getName()+",wj");
//AopOperation aopOperation = (AopOperation) context.getBean("aopOperationBean");
//aopOperation.queryOpLog();
//第二种方法
ShouldBeConfiguredBySpring myObject = (ShouldBeConfiguredBySpring) ctx.getBean("configuredBean");//必须是spring的bean才能拦截,自己定义的类springaop无法拦截
myObject.TestAop(); }
}
参考http://www.coderli.com/junit-spring-test-applicationcontext
spring-junit的标注总结的更多相关文章
- spring junit 做单元测试,报 Failed to load ApplicationContext 错误
spring junit 做单元测试,报 Failed to load ApplicationContext 错误. 查找了好一会,最后发现.@ContextConfiguration(locatio ...
- spring + junit 测试
spring + junit 测试 需要一个工具类 package com.meizu.fastdfsweb; import org.junit.runner.RunWith; import org. ...
- spring+junit单元测试
<1>读取文件: 配置文件在classes下:locations = {"classpath*:/spring/applicationContext.xml"} 配置文 ...
- spring junit
转载自 http://blog.csdn.net/funi16/article/details/8691575 在写单元测试的时候,一般是对数据库进行增删改查的操作,这个时候,如果之前删除了某条记录, ...
- Spring Junit 读取WEB-INF下的配置文件
假设Spring配置文件为applicationContext.xml 一.Spring配置文件在类路径下面 在Spring的java应用程序中,一般我们的Spring的配置文件都是放在放在类路径下面 ...
- Spring Junit集成测试
例子如下: package com.junge.demo.spring; import static org.junit.Assert.assertEquals; import java.util.L ...
- maven+spring+junit测试要注意的事情
使用maven方式创建webapp工程的资料网上一大堆,在这里也不详细说了.在创建完成之后,里面说到要转动态web工程时要切换为3.0版本,但是我本地切换不了,网上的方法好像也没用,暂时也没用到这块. ...
- JAVA框架 Spring junit整合单元测试
一.准备工作 1:Junit的需要的jar包: 2.spring的整合的jar包:spring-test-4.2.4.RELEASE.jar 3.代码实现 1) //导入整合的类,帮我们加载对应的配置 ...
- Spring+Junit测试用例的使用
1.[导包]使用Spring测试套件,需要两个jar包:junit-X.X.jar和spring-test-X.X.X.RELEASE.jar,在maven项目下可添加如下依赖: <depend ...
- Spring+Junit+Mock测试web项目,即Controller
准备:Maven依赖 <!-- Spring和MVC的包这里不列出来了,webmvc,aspects,orm,其他maven会自动导 --> <dependency> < ...
随机推荐
- 3.5 linux 0.11 目标文件格式
在Linux0.11系统中,GNU gcc或gas编译输出的目标模块文件和链接程序生成的可执行文件都使用了UNIX传统的a.out格式.这是一种被称为汇编与链接输出(Assembly & li ...
- REST简介及设计原则
rest,即REST(Representational State Transfer表述性状态转移)是一种针对网络应用的设计和开发方式,可以降低开发的复杂性,提高系统的可伸缩性. 简介 REST (R ...
- history对象属性和方法
history对象保存着用户上网的历史记录,从窗口被打开的那一刻算起,history是window对象的属性,因此每个浏览器窗口.每个标签页乃至每个框架,都有自 己的history对象和特定的wind ...
- web ajax跨域问题解决方案
jsonpHandler({ "code": "aaa", "price": 1780, "tickets": 5 ...
- ExtJS5_自定义菜单1
顶部和底部区域已经作好,在顶部区域有一个菜单的按钮,这一节我们设计一个菜单的数据结构,使其可以展示出不同样式的菜单.由于准备搭建的是一个系统模块自定义的系统,因此菜单也是自定义的,在操作员系统登录的时 ...
- maven学习心得
心得:这几天一直在研究maven的配置,还真是伤心啊,网上资料不多,而且问题不断.确实很让人头疼 背景:之所以学习maven是因为我们需要一键部署,我们项目是已经差不多完成了,是eclipse的web ...
- C++编程中对缓冲区的理解(OS默认4096大小的缓冲区,有例子,很形象)
什么是缓冲区缓冲区又称为缓存,它是内存空间的一部分.也就是说,在内存空间中预留了一定的存储空间,这些存储空间用来缓冲输入或输出的数据,这部分预留的空间就叫做缓冲区.缓冲区根据其对应的是输入设备还是输出 ...
- 软件发布版本区别介绍-Alpha,Beta,RC,Release
Alpha: Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用. 是希腊字母的第一位,表示最初级的版本 alpha就是α,beta就是β alpha版就是比 ...
- /etc/fstab自动挂载文件系统
打开 /etc/fstab 文件 [root@www ~]# vi /etc/fstab 默认情况下,fstab中已经有了当前的分区配置,内容可能类似: # <file system> & ...
- WordPress NextGEN Gallery ‘upload.php’任意文件上传漏洞
漏洞名称: WordPress NextGEN Gallery ‘upload.php’任意文件上传漏洞 CNNVD编号: CNNVD-201306-259 发布时间: 2013-06-20 更新时间 ...