(转)@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 配置要实现的功能都是一样 的,都是要降低程序间的耦合.只是配置的形 ...
随机推荐
- UWP自定义RadioButton实现Tab底部导航
先看效果: 参照Android的实现方式用RadioButton来实现,但是Uwp的RadioButton并没有安卓的Selector选择器 下面是一个比较简单的实现,如果有同学有更好的实现,欢迎留言 ...
- cadence pcb 设计学习记录提纲
Cadence软件是一款"一站式"的电气EDA软件系统.因能力所限,此处仅涉及使用cadence软件绘制PCB.日后随着对软件使用程度的加深,自己打算学习使用cadence软件的原 ...
- Android 的 SDK Manager 无法启动 闪退解决方法
[故障描述] 做 Android 开发就要下载 Android SDK,其中的 SDK Manager.exe 无法启动,一闪而过. 尝试重装 JDK.重新从官网下载 Android SDK.添加环境 ...
- Ipython 自动重载
一. 使用示例 In [1]: %load_ext autoreload In [2]: %autoreload 2 # Reload all modules (except those exclud ...
- fdisk 非交互式创建 分区
一. key 非交互式创建分区, 与 交互式创建分区区别不大. 使用 fdisk 的默认选项, 使用空行即可, 不用回车. 创建 主分区 和 扩展分区时, 需要注意 分区号 二. 创建主分区 fdis ...
- flask 扩展之 -- flask-sqlalchemy
flask-sqlalchemy.md 一. 安装 $ pip install flask-sqlalchemy 二. 配置 配置选项列表 : 选项 说明 SQLALCHEMY_DATABASE_UR ...
- Qt开发陷阱一QSTACKWIDGET
原始日期:2015-10-14 00:55 1.使用QStackWidget控件的setCurrentIndex方法时,要注意参数0对应着ui上StackWidget的page1,而不是page0,没 ...
- PHP+MySql实现后台数据的读取
我们使用的是PHP 的php_mysqli扩展 首先了解一些基础的用法 1.连接数据库使用 mysqli_connect() 参数:①主机地址 ②MYSQL用户名 ③MYSQL密码 ④选择 ...
- 探索Windows命令行系列(3):命令行脚本基础
1.实用功能 1.1.为脚本添加注释 1.2.控制命令的回显 1.3.使用数学表达式 1.4.向脚本传递参数 2.使用变量 2.1.变量的命名及定义 2.2.调用变量 2.3.变量的作用域 3.结构语 ...
- Swift初始化空字符串
为了构造一个很长的字符串,可以创建一个空字符串作为初始值.可以将空的字符串字面量赋值给变量,也可以初始化一个新的String 实例: var emptyString = "" // ...