场景:学习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注解说明的更多相关文章

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

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

  2. Spring @ContextConfiguration注解

    原文地址:https://www.cnblogs.com/bihanghang/p/10023759.html @ContextConfiguration这个注解通常与@RunWith(SpringJ ...

  3. @ContextConfiguration注解说明

    @ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件单个文件 @ContextConfiguration(Locations="../ap ...

  4. 在使用spring中的ContextConfiguration、test注解时出现的错误

    错误: 在使用测试注解时出现ContextConfiguration注解和test注解无法正常导包使用的编译异常,如图: 解决办法: 将pom.xml文件中以下依赖管理 中的<scope> ...

  5. Spring的基础注解

    Spring的基础注解 1.注解的概述 注解是为了便于程序的调试而用于代替配置文件的一种程序语法,与配置文件具有互换性.通常基于注解编程的程序更加简洁. (注:使用Spring注解必须导入aop包) ...

  6. Spring基于纯注解方式的使用

    经过上篇xml与注解混合方式,对注解有了简单额了解,上篇的配置方式极大地简化了xml中配置,但仍有部分配置在xml中进行,接下来我们就通过注解的方式将xml中的配置用注解的方式实现,并最终去掉xml配 ...

  7. @ContextConfiguration的意思

    @ContextConfiguration的意思 @ContextConfiguration这个注解通常与@RunWith(SpringJUnit4ClassRunner.class)联合使用用来测试 ...

  8. 在Spring使用junit注解进行单元测试

    在Spring中可以使用junit配合注解进行单元测试 一.常用注解 1.@RunWith(SpringJUnit4ClassRunner.class),让测试运行于spring测试环境2.@Cont ...

  9. SSM框架之Spring(3)IOC及依赖注入(基于注解的实现)

    Spring(3)IOC及依赖注入(基于注解的实现) 学习基于注解的 IoC 配置,大家脑海里首先得有一个认知,即注解配置和 xml 配置要实现的功能都是一样 的,都是要降低程序间的耦合.只是配置的形 ...

随机推荐

  1. github pages部署静态网页

    如果你的项目只是一个静态网站,就没有必要再去整什么服务器,github pages 提供了搭建静态网站的功能: 为什么使用Github Pages 1. 搭建简单而且免费: 2. 支持静态脚本: 3. ...

  2. checkbox全选、全不选实现

    <form   name=aa1   >         <p>           <input   type=checkbox   name="radiot ...

  3. “java.lang.IllegalArgumentException: Failed to evaluate expression ‘ROLE_USER’”报错的解决

    这个问题出现在Spring Security的相关配置中,找到原来的这一行: <security:intercept-url pattern="/**" access=&qu ...

  4. SpringMVC学习资料

    一.SpringMVC 1.helloworld 1.导包 <dependency> <groupId>org.springframework</groupId> ...

  5. C# 短信发送 邮件发送

    兴趣是最好的老师. --爱因斯坦 一.实现短信发送 1.使用短信mao的方式进行短信发送,前提要购买硬件设备,这里就不考虑展示了: 2.使用中国网建提供的短信平台,但是用几次后要收费: 我们这里主要介 ...

  6. 架构漫谈系列(2) 封装(Encapsulation)

    这是这个系列的第二篇.在第二篇里,我决定讲一讲封装. 程序的不同部分应该用封装去互相隔离,模块之间应该不应该产生很随意的关联. 可能有的人觉得不解,又或觉得是有道理的废话,不急,先一步一步来. 我们先 ...

  7. AI相关 TensorFlow -卷积神经网络 踩坑日记之一

    上次写完粗浅的BP算法 介绍 本来应该继续把 卷积神经网络算法写一下的 但是最近一直在踩 TensorFlow的坑.所以就先跳过算法介绍直接来应用场景,原谅我吧. TensorFlow 介绍 TF是g ...

  8. php7 安装yar 生成docker镜像

    Docker包含三个概念:(1)远程仓库即远程镜像库所有镜像的聚集地(不可进入操作).(2)本地镜像即从远程仓库拉取过来的镜像(3)运行起来的本地镜像叫做容器(分层的可操作)Docker使用:1.首先 ...

  9. 【Android Developers Training】 47. 序言:拍摄照片

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  10. Mathematica学习笔记1

    非常喜欢Mathematica的"自动草稿纸"的理念,Magic Paper, 唔哈~ Mathematica的矩阵操作和Matlab的风格十分不同. [ ] 是一个Part运算符 ...