场景:学习spring实战中相关的单元测试

1 正常使用

@ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件

1.1 单个文件

@ContextConfiguration(locations="../applicationContext.xml")

@ContextConfiguration(classes = SimpleConfiguration.class)

1.2 多个文件

可用{}

@ContextConfiguration(locations = { "classpath*:/spring1.xml", "classpath*:/spring2.xml" })

1.3 默认不写

可以根据测试的类名,去找到与之对应的配置文件。

异常情况:

异常信息

四月 12, 2017 9:38:10 上午 org.springframework.test.context.support.AbstractContextLoader generateDefaultLocations
信息: Could not detect default resource locations for test class [soundsystem.CNamespaceValueTest]: class path resource [soundsystem/CNamespaceValueTest-context.xml] does not exist
四月 12, 2017 9:38:10 上午 org.springframework.test.context.support.AnnotationConfigContextLoaderUtils detectDefaultConfigurationClasses
信息: Could not detect default configuration classes for test class [soundsystem.CNamespaceValueTest]: CNamespaceValueTest does not declare any static, non-private, non-final, inner classes annotated with @Configuration.

1

转载于:https://www.cnblogs.com/lixuwu/p/6697537.html

(转)@ContextConfiguration注解说明相关推荐

  1. Java配置文件找不到指定,使用@ContextConfiguration注解后,提示找不到配置文件

    intellij提示找不到配置文件 错误代码如下: 严重: Caught exception ] java.lang.IllegalStateException: Failed to load App ...

  2. junit 引入spring 注解管理_第05章 Spring 整合 Junit

    3.1 测试类中的问题和解决思路 3.1.1 问题 在测试类中,每个测试方法都有以下两行代码: ApplicationContext 这两行代码的作用是获取容器,如果不写的话,直接会提示空指针异常.所 ...

  3. @RunWith注解的作用

    @RunWith注解的作用 @RunWith就是一个运行器 @RunWith(JUnit4.class)就是指用JUnit4来运行 @RunWith(SpringJUnit4ClassRunner.c ...

  4. @RunWith和@ContextConfiguration的用法

    @RunWith作用: @RunWith 就是一个运行器 @RunWith(JUnit4.class) 就是指用JUnit4来运行 @RunWith(SpringJUnit4ClassRunner.c ...

  5. @configuration注解_SpringBoot的@Configuration扫盲

    @Configuration注解标识的类中声明了1个或者多个@Bean方法,Spring容器可以使用这些方法来注入Bean,比如: @Configuration public class AppCon ...

  6. Spring基于注解TestContext 测试框架使用详解

    原创整理不易,转载请注明出处:Spring基于注解TestContext 测试框架使用详解 代码下载地址:http://www.zuidaima.com/share/1775574182939648. ...

  7. @Configuration注解详解

    @Configuration注解详解 Configuration代码简介 Configuration注释类表明其主要目的是作为bean定义的源:@Configuration类允许通过调用同一类中的其他@B ...

  8. Spring testcontext

    Spring testcontext FROM: http://www.ibm.com/developerworks/cn/java/j-lo-spring25-test/ Spring 2.5 Te ...

  9. Spring 整合 Junit

    Spring 整合 Junit 问题 在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicationContext( ...

最新文章

  1. python opencv 录制视频_OpenCV Python 录制视频
  2. 产品经理思维模型:传播三大原理
  3. 服务器显示数据库,显示数据库服务器上的数据库数据库
  4. pat Simulation Test for PAT(B) 9月4日
  5. opensource项目_一月份的Opensource.com预览
  6. oracle入门很简单豆瓣,Oracle入门经典
  7. Vue 开发环境显示log信息
  8. MyBatis----resultMap的使用
  9. markdown编辑软件Ulysses 24.5 for Mac
  10. 三个箭头循环标志_摩托车6年免检,应该如何通过APP申请免检检验标志?
  11. 7.7-11 重定位过程描述+可执行目标文件的加载+共享库动态链接
  12. 数据结构视频教程 -《[北风网]C#版数据结构与算法高级教程》
  13. draft.js编辑器开发笔记
  14. 运维简历怎么写项目描述_应届生没有工作经验该怎么写简历?
  15. 冥王星P的编曲日志《我们就这样溺死在漩涡里》
  16. 是非人生 — 一个菜鸟程序员的5年职场路 第8节
  17. 正确理解差异的“专业意义”与“统计学意义”
  18. 百度云-人工智能-识别图片中的文字
  19. 使用HTML5,CSS。制作一个简单有新颖的“网易云音乐排行榜“。
  20. Kabuki即将推出VR购物平台,或是低配版Buy+

热门文章

  1. html页面视频标签,html5基础标签(html5视频标签 html5新标签用法)
  2. 《OpenCV3编程入门》学习笔记8 图像轮廓与图像分割修复(三)使用多边形将轮廓包围
  3. 经典dp最长递增子序列
  4. leetcode 解压缩_谁说 Python 的 shutil 不支持 7z 解压缩,我来教你扩展它的功能!...
  5. php thrift 报错,thrift安装遇到的问题以及解决方法(必看篇)
  6. matlab gui数据类型,MatLab GUI 数据传递
  7. python3程序下载安装_程序猿的语言,Python 3.7.0下载安装
  8. js手机键盘遮挡_完美解决手机网页中输入框被输入法遮挡的问题
  9. 素数c语言k1k2,1.编写一程序,输入两个整数k1,k2,(k1k2)。求出k1,k2间的素数...
  10. java批量执行sql语句_Java中批量执行sql语句