深入研究spring 必然少不了研究源码。
首先便是编译源码。源代码地址:https://github.com/spring-projects/spring-framework
将分支切换到稳定版本4.3.x分支,这样做是因为稳定版本出现的bug几率较小。
下面几个是编译安装的命令。
./gradlew install
./gradlew build
将spring 项目转为idea项目,具体可以参考目录下import-into-idea.md文件:
./gradlew cleanIdea
问题1:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':referencePdf'.
> [Java ](http://lib.csdn.net/base/java)heap space ...
看下错误日志,原来是内存溢出,需要调整 gradlew.bat文件中的 MaxHeapSize 的大小
set GRADLE_OPTS=-XX:MaxPermSize=512m -Xmx512m -XX:MaxHeapSize=512m %GRADLE_OPTS%
原文地址:http://306963591.iteye.com/blog/1677405
问题2:
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of input files for task 'distZip' during up-to-date check.
> java.io.FileNotFoundException: F:\study\spring-framework\build\distributions\spring-framework-4.3.11.BUILD-SNAPSHOT-schema.zip (The system cannot find the file specified)...
出现这个错误是因为windowns路径上的原因,我在ubuntu没有遇到这个问题。
运行在windows上需要修改build.gradle文件的两处,用注释给出,如下:
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 {
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 {
it.path.endsWith(schemas.get(key))
}
assert xsdFile != null
into (shortName) {
from xsdFile.path
}
}
}
}
替换成:
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 {
//这的路径需要改为\\
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 {
//这里需要进行路径替换
it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\'))
}
assert xsdFile != null
into (shortName) {
from xsdFile.path
}
}
}
}
3、问题3
org.springframework.ui.jasperreports.JasperReportsUtilsTests > renderAsCsvWithDataSource FAILED
java.lang.AssertionError at JasperReportsUtilsTests.java:206
org.springframework.ui.jasperreports.JasperReportsUtilsTests > renderAsXlsWithCollection FAILED
org.junit.ComparisonFailure at JasperReportsUtilsTests.java:231
org.springframework.ui.jasperreports.JasperReportsUtilsTests > renderAsXlsWithExporterParameters FAILED
org.junit.ComparisonFailure at JasperReportsUtilsTests.java:231
360 tests completed, 3 failed, 13 skipped
:spring-context-support:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':spring-context-support:test'.
> There were failing tests. See the report at: file:///F:/study/spring-framework/spring-context-support/build/reports/tests/index.html
这个问题也是在windows中遇到的,所以建议编译spring源码最好在liunx中,IDE最好用intellij idea ,
我的解决方案是,直接@Ignore遇到的这几个方法。
写作不易,最后展现一下成果吧,哈哈,算是自我鼓励:
image.png
网友评论