正确写法应该如下:

@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations="classpath: /com/config/spring-core.xml")
@ContextConfiguration("/com/config/spring-core.xml")
@Transactional

测试无错误的环境: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的更多相关文章

  1. 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中

  2. 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 ...

  3. 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 ...

  4. IDEA Junit FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist

    今天打算写一个单元测试,但是已经有写好的单元测试无论怎么弄都提示文件不存在,自己一度以为是启动方式不正确.这里简单记录一下处理过程 1 异常信息: Caused by: org.springframe ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 解决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 ...

  9. 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 ...

随机推荐

  1. 通过自关联替代开窗函数实现SQL优化

    数据库环境:SQL SERVER 2005 我们平时都是通过开窗析函数来取代自关联,减少表扫描,从而优化SQL.今天,反其道而行, 用自关联改写开窗函数.我们先来看一下SQL. 原SQL语句 SELE ...

  2. EL表达式 入门

    为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法. JSP EL语言定义 E L(Expression L ...

  3. C语言的奇技

    1.一个整型变量/字面值常量通常足够大,可以同时表示几个字符,所以有的C编译器允许字符常量/char及整型常量有多个字符.这表明当用' yes' 替代" yes" 时可能不会被发现 ...

  4. "const wchar_t is incompatible with parameter of type "LPCSTR"

    MessageBox(NULL, L"TEST", L"TEST", MB_OK); You may get this error if you "U ...

  5. 【HeadFirst设计模式】8.模板方法模式

    模板方法 定义: 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使用得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 策略模式: 定义一个算法家族,并让这些算法可以互 ...

  6. 如何使用命令提示符进入mysql

    如果mysql安装时的路径不是在C盘,应进入mysql的bin目录中,然后在命令提示符中输入“mysql -u USERNAME -pPASSWORD ” 如果如果mysql安装时的路径是在C盘,直接 ...

  7. 即时Web通信总结

    即时Web通信在一些对数据实时性要求特别严格的应用中十分重要,如监控系统.报价系统.股票交易系统和即时在线聊天应用等,由于http协议设计当初是为了服务器端响应客户端的请求而设计的,只能在客户端主动发 ...

  8. NGUI系列教程二

    接下来我们创建一个Label,NGUI->Open the Widget Wizard,打开widgetTool对话框,在Template中选择Label,确定AddTo右侧选项为panel,点 ...

  9. struts2用了哪几种模式

    代理模式 责任连模式 ActionVacation 迭代模式

  10. 区域生长算法的一种C++实现

    区域生长算法是一种图像分割方法,能够将图像中具有相同特征的连通区域分割出来,同时保证较好的边缘信息. 区域生长算法的优点是简单,容易实现:但空间和时间复杂度较高,对分割图像要求较高,否则容易形成孔洞和 ...