系统是后台是Spring+ibatis,Junit版本4.8.1,单元测试基类继承了AbstractTransactionalDataSourceSpringContextTests,但在单元测试的时候遇到一个诡异的问题,业务测试类继承了单元测试基类后,每次都刚好运行到第7个方法时报错了亮红了,错误如下:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in URL [file:F:/project/config/commonTest.xml]: Invocation of init method failed; nested exception is java.lang.OutOfMemoryError: Java heap space
看似好像是内存问题,但是把单元测试类的所有方法都清空注释掉,还是会报同样的错,太奇怪了,不知如何解决

解决方案 »

  1.   

    附上单元测试的基类如下:public class Junit4SpringTestBase extends
    AbstractTransactionalDataSourceSpringContextTests { @Override
    public void onSetUp() throws Exception {
    super.onSetUp();
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) this
    .getApplicationContext().getBeanFactory();
    GenericBeanDefinition define = (GenericBeanDefinition) beanFactory
    .getBeanDefinition("sqlMapClient");
    MutablePropertyValues pvalues = define.getPropertyValues(); PropertyValue pv = new PropertyValue("configLocation", "file:"
    + new File("").getAbsolutePath() + "/config/SqlMapConfig.xml");
    pvalues.setPropertyValueAt(pv, 0); pv = new PropertyValue("dataSource", beanFactory.getBean("dataSource"));
    pvalues.setPropertyValueAt(pv, 1);
    define.setPropertyValues(pvalues);
    beanFactory.registerBeanDefinition("sqlMapClient", define);
    }
    }