spring源码编译问题解决2,overflows the available area,schema.zip not exist,ApplicationContextExpressionTests

问题1 Line 1 of a paragraph overflows the available area by 37686mpt

原因:
异常翻译为:超出可用内存大小。
这是gradle编译时 jvm分配给gradle守护进程的堆内存不足导致无法生成文档异常。

解决办法:
在spring源代码根目录下修改gradle.properties文件,修改jvm堆内存分配大小

#gradle.properties代码末新增以下一行配置
#解决out ... 37648 prompt heap内存不够问题
org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

gradle守护进程配置参考/gradle官方文档

问题2 ‘***.BUILD-SNAPSHOT-schema.zip’ as it does not exist

原因:
异常翻译为:’***.BUILD-SNAPSHOT-schema.zip’ 该文件不存在,编译时生成出错,导致没有生成出来。
问题出在下面源码的 ’ / ’ 上,windows系统不能使用 ’ / ',要使用 ’ \ \ '。下图代码中key是包含 ’ / ’ 的字符串。
在这里插入图片描述
解决办法:
在根目录的build.gradle中修改代码,把整个函数块 task schemaZip(type: Zip){ } 替换为以下代码函数块。(实际所有代码中只修改了两行代码)

	//解决找不到***.BUILD-SNAPSHOT-schema.zip问题,修改替换'/'为'\\'
	task schemaZip(type: Zip) {
        group = "Distribution"
        baseName = "spring-framework"
        classifier = "schema"
        description = "Builds -${classifier} archive containing all " +
            "XSDs for deployment at http://springframework.org/schema."
        duplicatesStrategy 'exclude'
        moduleProjects.each { subproject ->
            def Properties schemas = new Properties();

            subproject.sourceSets.main.resources.find {
            	//修改代码行1,替换'/'为'\\'
                it.path.endsWith("META-INF\\spring.schemas")
            }?.withInputStream { schemas.load(it) }

            for (def key : schemas.keySet()) {
                def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
                assert shortName != key
                File xsdFile = subproject.sourceSets.main.resources.find {
                	//修改代码行2,替换'/'为'\\'
                    it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\'))
                }
                assert xsdFile != null
                into (shortName) {
                    from xsdFile.path
                }
            }
        }
    }

问题3 Class org.springframework.context.expression.ApplicationContextExpressionTests测试异常,报java.lang.AssertionError: expected: < val1 > but was: < val2 >异常

描述与分析:
根据异常报错查看对应reports下的index.html报表文件,发现failed原因是ApplicationContextExpressionTests类下的resourceInjection()。
异常信息
于是在源代码根目录搜索ApplicationContextExpressionTests.java,打开源代码搜索resourceInjection函数,找到源码如下:

	@Test
	public void resourceInjection() throws IOException {
		System.setProperty("logfile", "log4j.properties");
		try {
			AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ResourceInjectionBean.class);
			ResourceInjectionBean resourceInjectionBean = ac.getBean(ResourceInjectionBean.class);
			Resource resource = new ClassPathResource("log4j.properties");
			//assertEquals比较两个字符串是否内容相同,不相同时抛出检查性异常报错;相同则正常执行。
			//比较resouce与resourceInjectionBean.resource是否相等,例如:"aaa.xml".equals("aaa1.xml")
			assertEquals(resource, resourceInjectionBean.resource);
			assertEquals(resource.getURL(), resourceInjectionBean.url);
			assertEquals(resource.getURI(), resourceInjectionBean.uri);
			assertEquals(resource.getFile(), resourceInjectionBean.file);
			assertArrayEquals(FileCopyUtils.copyToByteArray(resource.getInputStream()),
					FileCopyUtils.copyToByteArray(resourceInjectionBean.inputStream));
			assertEquals(FileCopyUtils.copyToString(new EncodedResource(resource).getReader()),
					FileCopyUtils.copyToString(resourceInjectionBean.reader));
		}
		finally {
			System.getProperties().remove("logfile");
		}
	}

然后我们百度看assertEquals源码

//assertEquals会判断预测值expected与实际值actual是否相等,不等时会调用以下format()输出异常
public static String format(String message, Object expected, Object actual) {
    String formatted = "";
    if (message != null && message.length() > 0) {
        formatted = message + " ";
    }
    //错误按以下格式输出
    return formatted + "expected:<" + expected + "> but was:<" + actual + ">";
}

现在我们看这句抛出异常,会发现意思是val1和val2不同导致。
java.lang.AssertionError: expected: < val1 > but was: < val2 >

#异常翻译为:预测值与实际值不等,预测值应该val1,但却是val2,val1和val2要求相等
java.lang.AssertionError: expected: <file:/F:/study/bookStudy/spring%20framework/spring-framework-4.2.x/spring-context/build/resources/test/log4j.properties> but was:<file:/F:/study/bookStudy/spring%2520framework/spring-framework-4.2.x/spring-context/build/resources/test/log4j.properties>

那把val1和val2放到文本比较工具BCompare比一下,发现以下不同:
在这里插入图片描述
%20和%2520不同?这很奇怪,但是看这文本像是我存放spring源码的路径,于是到该路径匹配错误位置发现原因:应该路径文件名中的空格引起!路径文件名中应该是不能有空格。
在这里插入图片描述
原因:
存放spring源代码的路径有空格。

解决办法:
修改路径文件名,去除空格。
注意:路径名中有中文可能也会报错,请去除。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tazuxianzai

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值