成功编译(不代表就完全成功,需要测试成功才是最终成功)
![dd8110299b03f2aa1a84721b756efc7c.png](https://i-blog.csdnimg.cn/blog_migrate/b2ac0c7c8d4ff6040d3a51ee62711294.jpeg)
测试成功
![7b4e07b098824a1ea502f6fc2533286e.png](https://i-blog.csdnimg.cn/blog_migrate/9ecbabe2e39bfd3bd1a037bddf622fa8.jpeg)
看到项目调试成功,那就可以开启我们的源码学习之路啦!!!!错误信息汇总:
1、TASK API:这个任务出现error,大都是javadoc出现问题,确定为JDK版本不对
正确做法是换为我们要求的JDK版本即可!
2、成功编译后,运行自己的测试项目报错:找不到InstrumentationSavingAgent
![6902a40f320d41ead4dcd82fadda3f1a.png](https://i-blog.csdnimg.cn/blog_migrate/1006d87775aed585cd54e62f321b4ca6.jpeg)
正确做法是spring-context.gradle修改 optional(project(":spring-instrument"))为 compile(project(":spring-instrument")),然后重新编译一下spring-context(compileTestJava+build),完美解决!
1、编译流程1.1、环境搭建:JDK1.8.0_211、GRADLE4.9、IDEA2019.1.2
JDK:jdk1.8.0_211(推荐这个版本)链接
![98c1c0139d5701a57f7abbfbb64d4cc1.png](https://i-blog.csdnimg.cn/blog_migrate/55b2a1e710234f6359fed3f58ce3ebca.jpeg)
![61f65c9ba2a662d8100d46c4a737b60a.png](https://i-blog.csdnimg.cn/blog_migrate/be234c0987e29d5e20b0b545a2e9e4e9.jpeg)
Gradle:gradle4.9链接
Gradle的GRADLE_HOME环境配置和Java配置JAVA_HOME是一样的
记得在Path中配置%GRADLE_HOME%bin
![0bfe07b0506a9a1a2518a698af1e7d4a.png](https://i-blog.csdnimg.cn/blog_migrate/77a103121d709cda42d9347f424ae095.jpeg)
![60072bd1c9339d0cc12ac3bc7a547069.png](https://i-blog.csdnimg.cn/blog_migrate/b571a1bb2734f61a6c17ec25a401b184.jpeg)
IDEA:IDEA 2019.1.2
1.2、将源码导入IDEA
在IDEA中File->Open将源码的文件夹导入
![4e807a4781f11cbd84aafb5771e14bf2.png](https://i-blog.csdnimg.cn/blog_migrate/bb828fd148982f70515b367c54132322.jpeg)
1、点击auto-import
2、点击使用本地的gradle
3、JVM环境设置为你的jdk1.8.0_211,也就是列表里的JAVA_HOME选项
4、在这里面配置vm选项
点击
![1b15d61c1fd0e9bce8e6d1401e8eb4b4.png](https://i-blog.csdnimg.cn/blog_migrate/8e4f7dfea5c5414505f82a85ed4cd8bb.png)
设置VM为XX:MaxMetaspaceSize=2048m -Xmx2048m -XX:MaxHeapSize=1024m
点击ok即可
1.3、修改文件
![fe5de695ca33156291370911de1b45e9.png](https://i-blog.csdnimg.cn/blog_migrate/b7a7335c8965261470b14d5b4d2f6804.jpeg)
第一步:注释DOKKA和ASCIIDOCTOR
- /*dokka {
- dependsOn {
- tasks.getByName("api")
- }
- doFirst {
- classpath = subprojects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
- classpath += files(subprojects.collect { it.sourceSets.main.compileClasspath })
- }
- moduleName = "spring-framework"
- outputFormat = "html"
- outputDirectory = "$buildDir/docs/kdoc"
- sourceDirs = files(subprojects.collect { project ->
- def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
- kotlinDirs -= project.sourceSets.main.java.srcDirs
- })
- externalDocumentationLink {
- url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
- packageListUrl = new File(buildDir, "api/package-list").toURI().toURL()
- }
- externalDocumentationLink {
- url = new URL("https://projectreactor.io/docs/core/release/api/")
- }
- externalDocumentationLink {
- url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
- }
- }
- asciidoctor {
- sources {
- include '*.adoc'
- }
- resources {
- from(sourceDir) {
- include 'images/*', 'stylesheets/*', 'tocbot-3.0.2/*'
- }
- }
- logDocuments = true
- backends = ["html5"]
- // only ouput PDF documentation for non-SNAPSHOT builds
- if(!project.getVersion().toString().contains("BUILD-SNAPSHOT")) {
- backends += "pdf"
- }
- options doctype: 'book', eruby: 'erubis'
- attributes 'icons': 'font',
- 'idprefix': '',
- 'idseparator': '-',
- docinfo: '',
- revnumber: project.version,
- sectanchors: '',
- sectnums: '',
- 'source-highlighter': 'coderay@', // TODO switch to 'rouge' once supported by the html5 backend
- stylesdir: 'stylesheets/',
- stylesheet: 'main.css',
- 'spring-version': project.version
- }*/
第二步:修改SCHEMAZIP的两处位置,看注释行
task schemaZip(type: Zip) {
group = "Distribution"
baseName = "spring-framework"
classifier = "schema"
description = "Builds -${classifier} archive containing all " +
"XSDs for deployment at https://springframework.org/schema."
duplicatesStrategy 'exclude'
moduleProjects.each { subproject ->
def Properties schemas = new Properties();
subproject.sourceSets.main.resources.find {- //此处修改为
it.path.endsWith("META-INFspring.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 {- //此处将Linux路径符号替换为Windows路径符号
it.path.endsWith(schemas.get(key).replaceAll('/',''))
}
assert xsdFile != null
into (shortName) {
from xsdFile.path
}
}
}
}
1.4、预编译
第一步:打开源码文件夹中的
![861e9b7ac3487eef8408779250f5109d.png](https://i-blog.csdnimg.cn/blog_migrate/3c3f6f2330eac7b37a9afe2fca47c9cf.jpeg)
![6b0f58569b55a8f47bf5de3c160ca660.png](https://i-blog.csdnimg.cn/blog_migrate/109f4df239bba85a19355fd7654642ec.jpeg)
spring-oxm和spring-core需要预先编译
第二步:预编译
打开gradle面板,找到各个源码模块,然后双击compileTestJava
![011c68669eae1d108aa1c2245ca11d6d.png](https://i-blog.csdnimg.cn/blog_migrate/c643b565c651e5cd5634663f1d29502f.jpeg)
![fd96cf39260092d0ab7ef5df69914ce5.png](https://i-blog.csdnimg.cn/blog_migrate/b6b37ba113005fd3646d5a023b2a819c.jpeg)
![46be867ecef05b16b8e16a1ac62b8de5.png](https://i-blog.csdnimg.cn/blog_migrate/afbe260848f651c2ea45ff1caa079a17.jpeg)
第三步:整体编译
![2881ed162a92b46d957c67e760827298.png](https://i-blog.csdnimg.cn/blog_migrate/2ac30ffa0ca3c3be7af3f8a5a50753c9.jpeg)
等待即可,大概20-40分钟
![dd8110299b03f2aa1a84721b756efc7c.png](https://i-blog.csdnimg.cn/blog_migrate/b2ac0c7c8d4ff6040d3a51ee62711294.jpeg)
2、测试模块
在源码项目new一个moudle,类型为gradle的管理的java项目即可
![dc9722ce0f86dbfb53cf43c8a212e9b7.png](https://i-blog.csdnimg.cn/blog_migrate/23c612d67d6d2966523a763971961373.jpeg)
自己使用注解测试一下即可
![460fe8afac22db272e9d211ac2ee7fe5.png](https://i-blog.csdnimg.cn/blog_migrate/e2e1016013af9b91e0475f29a137f9ef.jpeg)
UserDao.java
package com.lpf.dao;
import org.springframework.stereotype.Repository;
@Repository
public class UserDao {
public void printInfo(){
System.out.println("user dao");
}
}
Test.java
package com.lpf.test;
import com.lpf.dao.UserDao;
import com.lpf.utils.AnnotationConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Test {
public static void main(String[] args) {
AnnotationConfigApplicationContext ac=new
AnnotationConfigApplicationContext(AnnotationConfig.class);
UserDao userDao=(UserDao) ac.getBean(UserDao.class);
userDao.printInfo();
}
}
AnnotationConfig.java
package com.lpf.utils;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.lpf")
public class AnnotationConfig {
}
build.gradle添加compile project(":spring-context")
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile project(":spring-context")
}
运行Test.java,出现下图即证明spring5.1.x项目完美部署成功!
![7b4e07b098824a1ea502f6fc2533286e.png](https://i-blog.csdnimg.cn/blog_migrate/9ecbabe2e39bfd3bd1a037bddf622fa8.jpeg)