分配置文件在classpath下和web-inf下两种情况的加载:

ApplicationContext context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
new ClassPathXmlApplicationContext("applicationContext.xml");// 从classpath中加载
new FileSystemXmlApplicationContext("classpath:地址");// 没有classpath表示当前目录

  

注解加载

@org.springframework.test.context.ContextConfiguration(locations={"file:WebRoot/WEB-INF/applicationContext.xml"}) 

@org.springframework.test.context.ContextConfiguration(locations={"classpath:applicationContext.xml"})

  

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:/ut/applicationContext.xml"})
public class ScanDecisionFileTest { @Before
public void setUp() throws Exception {
} @After
public void tearDown() throws Exception {
} @Test
public void testRun() {
//fail("Not yet implemented");
} }

  

Junit手动/自动加载spring配置文件的更多相关文章

  1. Junit(手动/自动)加载

    ssm中测试service层数据 Junit手动加载配置文件 package com.oukele.bookshop_ssm.service; import org.junit.After; impo ...

  2. ssh整合思想初步 struts2与Spring的整合 struts2-spring-plugin-2.3.4.1.jar下载地址 自动加载Spring中的XML配置文件 Struts2下载地址

    首先需要JAR包 Spring整合Structs2的JAR包 struts2-spring-plugin-2.3.4.1.jar 下载地址 链接: https://pan.baidu.com/s/1o ...

  3. Spring:在web.xml正确加载spring配置文件的方式

    web.xml加载spring配置文件的方式主要依据该配置文件的名称和存放的位置不同来区别,目前主要有两种方式. 1. 如果spring配置文件的名称为applicationContext.xml,并 ...

  4. 在web.xml正确加载spring配置文件的方式

    ssm框架整合时一直报出没有创建实例bean的错误,一直以为是代码原因,反复测试了很久,才找到原因是spring配置文件没有正确导入,下图是我的错误示例 web.xml加载spring配置文件的方式主 ...

  5. junit测试用例加载spring配置文件

    junit加载pom引用项目的xml配置文件,如果定义了<beans profile="dev">,必须在测试用例类上面加上标记 @ActiveProfiles(&qu ...

  6. spring动态加载(刷新)配置文件 [复制链接]

    待验证 在程序开发时,通常会经常修改spring的配置文件,不得不重启tomcat来加载spring配,费时费力.如果能在不重启tomcat的情况下,手动动态加载spring 配置文件,动态重启读取s ...

  7. Spring Web项目spring配置文件随服务器启动时自动加载

    前言:其实配置文件不随服务器启动时加载也是可以的,但是这样操作的话,每次获取相应对象,就会去读取一次配置文件,从而降低程序的效率,而Spring中已经为我们提供了监听器,可监听服务器是否启动,然后在启 ...

  8. spring的applicationContext.xml如何自动加载

    一个web工程自动加载的配置文件只有web.xml,想要加载其他.xml必须在web.xml里面进行配置. 用spring的时候需要一个bean容器来管理所有的bean,所有bean默认是写在appl ...

  9. Spring加载XML配置文件

    原创链接:http://www.cnblogs.com/yanqin/p/5282929.html(允许转载,但请注明原创链接) BeanFactory加载单个文件 当使用beanfactory去获取 ...

随机推荐

  1. iOS:开发者中心证书创建流程

    一,首先点击开发者首页(https://developer.apple.com/)里面的Member Center.二,输入开发者账号和密码,点击sign in登录.三,点击Certificates, ...

  2. LCA(RMQ)

    ; xh=; ..lx*] of longint; lt,dfn,fr,dep:..lx] of longint; f:..lx*,..xh] of longint; vis:..lx] of boo ...

  3. strlen和mb_strlen的区别

    在php中常见的计算字符串长度的函数有:strlen和mb_strlen.当字符全是英文字符的时候,两者是一样.这里主要比较一下,中英文混排的时候,两个计算结果. 在PHP中,strlen与mb_st ...

  4. wddm 部署问题解决

    在把wddm部署到一台老的服务上的 windows server 2003 上时遇到了问题,之前也在 windows server 2003 上装过,但是并没有遇到问题,估计和服务器比较老有关系. 问 ...

  5. QMP ( qemu monitor protocol ) and Different ways of accessing it

    The QEMU Monitor Protocol (QMP) is a JSON-based protocol which allows applications to communicate wi ...

  6. OpenvSwitch架构

    Openvswitch的架构 数据库结构和OVS-VSCTL # ps aux | grep openvswitch root      1117  0.0  0.0  21200  1580 ?   ...

  7. Python编程小记

    发现这种结构很实用: while True: expression .... if condition: expression break 好吧,我承认我是菜鸟-

  8. mysql样例数据库employees

    Oracle和sqlserver都有基于员工信息的样例数据库,同样mysql上也是有的. 给出一个连接地址https://github.com/datacharmer/test_db. 下载后直接调用 ...

  9. centos彻底删除文件夹、文件命令(centos 新建、删除、移动、复制等命令)

    centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkdir 文件名 新建一个名为test的文件夹在home下 view source1 mkdir ...

  10. Mac中Fn键技巧

    此文适用:Mac自带苹果键盘或外接有Fn键的普通键盘 上一页=Fn+⬅️ 下一页=Fn+➡️ 向上卷动=Fn+⬆️ 向下卷动=Fn+⬇️