zoukankan      html  css  js  c++  java
  • spring junit class path resource [ /com/config/spring-core.xml] cannot be opened because it does not exist


     正确写法应该如下:

    @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;
           }
    }

  • 相关阅读:
    让Oracle高效并行执行的13个必备知识点
    oracle使用并行踩过的坑
    oracle parellel 案例
    并行查询 最基本
    ORACLE parallel 3个层面的影响
    Mac下百度网盘破解
    vscode整个项目的查找替换快捷键
    mysql---group_concat
    mysql-group by 与 where
    npm安装指定版本包
  • 原文地址:https://www.cnblogs.com/whaozl/p/5360993.html
Copyright © 2011-2022 走看看