zoukankan      html  css  js  c++  java
  • Spring整合JUnit4测试使用注解引入多个配置文件

    转自:https://kanpiaoxue.iteye.com/blog/2151903

    我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个。我们在类的注释上面会这样写:

    Java代码  收藏代码
    1. @RunWith(SpringJUnit4ClassRunner.class)  
    2. @ContextConfiguration(locations = "classpath*:spring-ctx-application.xml") 

     但有的时候我们的项目很复杂,其中的spring配置文件被拆分成了多个,这样该如何写上面这段单测代码而引入多个配置文件呢?如下:

    Java代码  收藏代码
    1. @RunWith(SpringJUnit4ClassRunner.class)  
    2. @ContextConfiguration(locations = { "classpath*:spring-ctx-application.xml",  
    3.         "classpath*:spring-ctx-consumer.xml" })  

     这样就可以轻松的引入多个spring的配置文件了。

    或者配置符合某一个正则表达式的一类文件,如:

    Java代码  收藏代码
      1. @RunWith(SpringJUnit4ClassRunner.class)  
      2. @ContextConfiguration(locations = "classpath*:spring-ctx-*.xml") 
  • 相关阅读:
    简单说说 Java 的 JVM 内存结构
    cpu怎么实现运算的
    triplet
    LCT的一些坑【已经变成坑点集合了233】
    插头DP学习笔记
    一个坑-卡常
    NOIP2017游记
    洛谷P4015 运输问题
    线性基学习笔记
    洛谷P4331[BOI2004] sequence
  • 原文地址:https://www.cnblogs.com/sharpest/p/7719892.html
Copyright © 2011-2022 走看看