`

java.lang.ClassNotFoundException: org.junit.Assume$AssumptionViolatedException

 
阅读更多

_____构造方法“惹的祸”

__________________________________________________________________________________________

 

网上有很多同仁遇到这样的问题: 项目中使用spring testcontext和junit做测试工作, 使用的时候出现如下情形:org/junit/Assume$AssumptionViolatedException; nested exception is java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException  

归结的原因是:Spring2.5 的Sring-Test对于JUnit有个累人的要求,JUnit的版本必须是4.4,不支持高版本(如4.5、4.7等) 。否则,会产生 java.lang.ClassNotFoundException: org.junit.Assume$AssumptionViolatedException 异常。 

另外有一篇文章http://teddywang.iteye.com/blog/652215 也写得较好,可以认真的读一下,对于spring-test-2.5.6.jar和junit-4.4.jar, 在此我把我遇到的问题做一些补充,至于说 Spring2.5.X与Junit4.5兼容性问题我没有再去深入研究。

我使用的就是Spring2.5.X与Junit4.10最新版本,我测试一个方法的时候总是出现java.lang.ClassNotFoundException: org.junit.Assume$AssumptionViolatedException 的异常,后来才发现是由于构造方法的问题。代码分享如下:

hql语句:

StringBuffer hql = new StringBuffer(
				"select new DeptScoreCounter(o.id,o.deptName,o.year,o.quarter,o.halfyear,sum(o.total),sum(o.bmImportSum),sum(o.bmEverydaySum),sum(o.zjImportSum),sum(o.zjEverydaySum),sum(o.bmImportGoodSum),sum(o.bmImportGenericSum),sum(o.bmEverydayGoodSum),sum(o.bmEverydayGenericSum),sum(o.bmCommonGoodSum),sum(o.bmCommonGenericSum),sum(o.zjImportGoodSum),sum(o.zjImportGenericSum),sum(o.zjEverydayGoodSum),sum(o.zjEverydayGenericSum),sum(o.zjCommonGoodSum),sum(o.zjCommonGenericSum))")
				.append(" from DeptScoreCounter o where 1=1 and o.year=?")
				.append(" and o.halfyear=?").append(" and o.deptName=?");

 注意,sum之后得到的是long型,所以DeptScoreCounter中的构造方法的类型也要对应为long型,否则报主题错误!因为我的属性原来为Integer类型,构造方法也写了Integer型,才带来了主题错误。

hql查询new应该有对应构造方法:

public DeptScoreCounter(String id, String deptName, String year,
			Integer quarter, Integer halfyear, Long total,
			Long bmImportSum, Long bmEverydaySum, Long zjImportSum,
			Long zjEverydaySum, Long bmImportGoodSum,
			Long bmImportGenericSum, Long bmEverydayGoodSum,
			Long bmEverydayGenericSum, Long bmCommonGoodSum,
			Long bmCommonGenericSum, Long zjImportGoodSum,
			Long zjImportGenericSum, Long zjEverydayGoodSum,
			Long zjEverydayGenericSum, Long zjCommonGoodSum,
			Long zjCommonGenericSum) {
		Id = id;
		this.deptName = deptName;
		this.year = year;
		this.quarter = quarter;
		this.halfyear = halfyear;
		this.total = total.intValue();
		this.bmImportSum = bmImportSum.intValue();
		this.bmEverydaySum = bmEverydaySum.intValue();
		this.zjImportSum = zjImportSum.intValue();
		this.zjEverydaySum = zjEverydaySum.intValue();
		this.bmImportGoodSum = bmImportGoodSum.intValue();
		this.bmImportGenericSum = bmImportGenericSum.intValue();
		this.bmEverydayGoodSum = bmEverydayGoodSum.intValue();
		this.bmEverydayGenericSum = bmEverydayGenericSum.intValue();
		this.bmCommonGoodSum = bmCommonGoodSum.intValue();
		this.bmCommonGenericSum = bmCommonGenericSum.intValue();
		this.zjImportGoodSum = zjImportGoodSum.intValue();
		this.zjImportGenericSum = zjImportGenericSum.intValue();
		this.zjEverydayGoodSum = zjEverydayGoodSum.intValue();
		this.zjEverydayGenericSum = zjEverydayGenericSum.intValue();
		this.zjCommonGoodSum = zjCommonGoodSum.intValue();
		this.zjCommonGenericSum = zjCommonGenericSum.intValue();
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics