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

  • 相关阅读:
    Mysql事务隔离级
    51nod1076(tarjan)
    求无向图的割点和桥模板(tarjan)
    51nod1770(xjb)
    51nod1640(kruscal)
    51nod1639(组合数学)
    51nod1625(枚举&贪心)
    51nod1562(set&模拟)
    51nod1483(打表)
    51nod1475(贪心&枚举)
  • 原文地址:https://www.cnblogs.com/whaozl/p/5360993.html
Copyright © 2020-2023  润新知