(转)@ContextConfiguration注解说明
场景:学习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
(转)@ContextConfiguration注解说明的更多相关文章
- 使用@ContextConfiguration注解后,提示找不到配置文件
intellij提示找不到配置文件 错误代码如下: 严重: Caught exception ] java.lang.IllegalStateException: Failed to load App ...
- Spring @ContextConfiguration注解
原文地址:https://www.cnblogs.com/bihanghang/p/10023759.html @ContextConfiguration这个注解通常与@RunWith(SpringJ ...
- @ContextConfiguration注解说明
@ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件单个文件 @ContextConfiguration(Locations="../ap ...
- 在使用spring中的ContextConfiguration、test注解时出现的错误
错误: 在使用测试注解时出现ContextConfiguration注解和test注解无法正常导包使用的编译异常,如图: 解决办法: 将pom.xml文件中以下依赖管理 中的<scope> ...
- Spring的基础注解
Spring的基础注解 1.注解的概述 注解是为了便于程序的调试而用于代替配置文件的一种程序语法,与配置文件具有互换性.通常基于注解编程的程序更加简洁. (注:使用Spring注解必须导入aop包) ...
- Spring基于纯注解方式的使用
经过上篇xml与注解混合方式,对注解有了简单额了解,上篇的配置方式极大地简化了xml中配置,但仍有部分配置在xml中进行,接下来我们就通过注解的方式将xml中的配置用注解的方式实现,并最终去掉xml配 ...
- @ContextConfiguration的意思
@ContextConfiguration的意思 @ContextConfiguration这个注解通常与@RunWith(SpringJUnit4ClassRunner.class)联合使用用来测试 ...
- 在Spring使用junit注解进行单元测试
在Spring中可以使用junit配合注解进行单元测试 一.常用注解 1.@RunWith(SpringJUnit4ClassRunner.class),让测试运行于spring测试环境2.@Cont ...
- SSM框架之Spring(3)IOC及依赖注入(基于注解的实现)
Spring(3)IOC及依赖注入(基于注解的实现) 学习基于注解的 IoC 配置,大家脑海里首先得有一个认知,即注解配置和 xml 配置要实现的功能都是一样 的,都是要降低程序间的耦合.只是配置的形 ...
随机推荐
- 2015阿里巴巴安全峰会PPT
有幸参加了阿里巴巴安全峰会,不得不佩服阿里巴巴神盾局,真牛B!然后亲眼目睹了第二天的各大厂商牛(zhuang)B人才上台演讲,有被捧的,有被喷的,呵呵.总的来说,大家的分享精神还是阔以的. 下面是会议 ...
- eclipse 好用的插件总结
改变eclipse的背景色,各种关键词颜色的插件. color theme. 在mac下最好是通过手动复制粘贴jar文件到, eclipse的plugins下面. 通过Install new soft ...
- 开发抓包工具 Mac charles 3.11.5 破解版 安装包
摘要 在发开过程中,追踪请求和监控请求与返回数据是我们经常会需要的一个需求,在Mac端,Charles是一款非常易用的抓包工具. 一.简介 Charles是Mac端的一款截取与分析网络请求的工具,在网 ...
- ecshop调用指定分类和个数的文章列表
举例如首页调用方法: 1.先打开index.php文件找到以下代码: $smarty->assign('new_articles', index_get_new_articles()); // ...
- 如何在非 React 项目中使用 Redux
本文作者:胡子大哈 原文链接:https://scriptoj.com/topic/178/如何在非-react-项目中使用-redux 转载请注明出处,保留原文链接和作者信息. 目录 1.前言 2. ...
- HTML行内元素、块状元素、行内块状元素的区别
HTML可以将元素分类方式分为行内元素.块状元素和行内块状元素三种.首先需要说明的是,这三者是可以互相转换的,使用display属性能够将三者任意转换: (1)display:inline;转换为行内 ...
- Example017简单的下拉框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- angularLoad(用以异步加载js文件)
angularLoad(用以异步加载js文件) 使用方法: 1.执行命令 下载 lib npm install angular-load --save 2.index.html引用js <scr ...
- php imagemagick 处理 图片剪切、压缩、合并、插入文本、背景色透明
php有一款插件叫做imagemagick,功能很强大,提供了图片的很多操作,图片剪切.压缩.合并.插入文本.背景色透明等.并且有api方法调用和命令行操作两种方式,如果只是简单处理的话建议api方法 ...
- 一张图告诉你angular2所有知识点
忙活了半年,从angular2.0到现在angular4.2.从没AOT到有AOT.我想说,angular2的学习曲线真的有点陡峭.只能说,angular2是一个比较完整的框架,框架就是这样,一大堆条 ...