spring junit class path resource [ /com/config/spring-core.xml] cannot be opened because it does not exist
正确写法应该如下:
测试无错误的环境:spring4.2.5 junit4.10
参考:http://www.ibm.com/developerworks/cn/java/j-lo-springunitest/
http://my.oschina.net/dlpinghailinfeng/blog/336694
特别感谢以上2篇文章,尤其IBM的,果然是顶级,其他人写的基本错误,看到IBM后,尤为开心,秒杀解决问题。
其他类继承SpringTest 即可。
package com.test;import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations="classpath: /com/config/spring-core.xml")
@ContextConfiguration("/com/config/spring-core.xml")
@Transactional
public class SpringTest extends AbstractJUnit4SpringContextTests {
public <T> T getBean(Class<T> type){
return applicationContext.getBean(type);
}
public Object getBean(String beanName){
return applicationContext.getBean(beanName);
}
protected ApplicationContext getContext(){
return applicationContext;
}
}
spring junit class path resource [ /com/config/spring-core.xml] cannot be opened because it does not exist的更多相关文章
- java.io.FileNotFoundException: class path resource [bean/test/User.hbm.xml] cannot be opened because it does not exist
确定下 WEB-INF/classes下有没有,不是src下哦 工程的src下创建后,会发布到tomcat下项目下的classes中
- Caused by: java.io.FileNotFoundException: class path resource [../../resources/config/spring.xml] cannot be opened because it does not exist
在尝试使用Spring的Test的时候遇到了这个错误 原来的代码: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loca ...
- spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
spring 整合Mybatis 运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:class path reso ...
- IDEA Junit FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist
今天打算写一个单元测试,但是已经有写好的单元测试无论怎么弄都提示文件不存在,自己一度以为是启动方式不正确.这里简单记录一下处理过程 1 异常信息: Caused by: org.springframe ...
- Spring报错:java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
感谢:http://blog.chinaunix.net/uid-20681545-id-184633.html提供的解决方案,非常棒 ! 问题说明: 新建一个Spring项目,新建一个Bean类:H ...
- idea的maven项目运行出错_java.io.FileNotFoundException: class path resource [spring/sprint-tx.xml] cannot be opened because it does not exist
前提:idea maven ssm 错误信息如下: 严重: Exception sending context initialized event to listener instance of ...
- MyBatis笔记----报错:Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/ij34/mybatis/applicationContext.xml]: Invocation of init method failed; nested exception is org.sp
四月 05, 2017 4:51:02 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRef ...
- 解决CXF的java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist
以下是错误信息 九月 25, 2017 8:22:04 下午 org.springframework.web.context.support.XmlWebApplicationContext prep ...
- maven项目启动报错;class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not exist
项目启动报了一堆错误,其实都是class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not ...
随机推荐
- MongoDB下载安装
MongoDB官方下载地址:http://www.mongodb.org/ 一.在Windows平台下的安装 1.下载MongoDB数据库 2.设置MongoDB程序存放目录 下载完数据库后,直接解压 ...
- ### 线性回归(Regression)
linear regression logistic regression softmax regression #@author: gr #@date: 2014-01-21 #@email: fo ...
- ###Git使用问题
#@date: 2014-05-04 #@author: gerui #@email: forgerui@gmail.com 一.git reset的使用 今天修改了代码,就git add ./,添加 ...
- CentOS配置java运行环境
CentOS_配置_docker CentOS_6.5 1.CentOS_6.5在安装docker-io之前需要首先卸载docker包(没下载过可以省略) $ sudo yum -y remove d ...
- String练习
/*1,模拟一个trim方法,去除字符串两端的空格. 思路: 1,判断字符串第一个位置是否是空格,如果是继续向下判断,直到不是空格为止. 结尾处判断空格也是如此. 2, ...
- poj代码搬家啦啦啦
我的poj代码搬家啦,大家想看可以到 blog.csdn.net/michaelysm 来看.欢迎哦
- OS X平台上MySQL环境搭建
参考资料: http://www.cnblogs.com/macro-cheng/archive/2011/10/25/mysql-001.html http://blog.csdn.net/just ...
- RX学习笔记:JavaScript数组操作
RX学习笔记:JavaScript数组操作 2016-07-03 增删元素 unshift() 在数组开关添加元素 array.unshift("value"); array.un ...
- preg_match_all, preg_match
int preg_match(string $pattern, string $subject[, $arr][, int $flags]);$pattern 正则表达式$subject: 要搜索的字 ...
- entity framework mysql 那些写法你碰不得
记 几次 ef 数据查询踩到的坑......未完待续