Spring source compiler, import IDEA, debugging source code

Install Gradle

Because Spring is Gradle project management, so you have to first install Gradle

Access https://services.gradle.org/distributions/, download the required binary packages

New environment variable
GRADLE_HOME D: \ Program Files \ gradle -4.8
after the Path variable plus;% GRADLE_HOME% \ bin (win10, then add a record no;)

Command line input

gradle -v

It said output version installed correctly

spring github project Address:
https://github.com/spring-projects/spring-framework

After compiling import IDEA

Execute the following command in spring-framework folder

gradlew :spring-oxm:compileTestJava

Due to the way the network may fail to execute it several times, was last seen BUILD SUCCESSFUL to

When importing selected by local downloaded to gradle
Here Insert Picture Description
and other projects has been to compile, I encountered a problem halfway to locate the three lines of code, put it annotated

spring-beans.gradle

// compileGroovy.dependsOn = compileGroovy.taskDependencies.values - "compileJava"
// compileKotlin.dependsOn(compileGroovy)
// compileKotlin.classpath += files(compileGroovy.destinationDir)

Middle may encounter Skipped due to earlier error, every time I refresh the download
Here Insert Picture Description
finally succeeded

The establishment of sub-module source code debugging

File-> New-> Module
Here Insert Picture Description
GroupId-> org.springframework
Version-> 5.0.17.BUILD-SNAPSHOT (gradle.properties may know from the project file)

  1. Delete the files in the module build settings.gradle
  2. After settings.gradle under the spring items plus the following sentence include (whose name I built module) "learning-spring"
  3. Join spring-context-dependent in the new module, put about my build.gradle
plugins {
    id 'java'
}

group 'org.springframework'
version '5.0.17.BUILD-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile project(':spring-context')
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Create a configuration class

@Configuration
@ComponentScan("com.javashitang")
public class AppConfig {


}
@Repository
public class UserDao {

	public String getUser() {
		return "user";
	}
}

Test category

public class Main {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
		UserDao userDao = context.getBean(UserDao.class);
		String str = userDao.getUser();
		System.out.println(str);
	}
}

When running up a test project found that this class can not be found

org.springframework.instrument.InstrumentationSavingAgent

The spring-context.gradle module, the contents read as follows

# 修改前
optional(project(":spring-instrument"))
# 修改后
compile(project(":spring-instrument"))

Rerun the test project, the normal output, the normal debugging

GitHub address

https://github.com/erlieStar/spring-framework

Reference blog

[1]https://blog.csdn.net/bskfnvjtlyzmv867/article/details/81171802
[2]https://blog.csdn.net/Lin_xiaofeng/article/details/87923075

Published 385 original articles · won praise 1471 · Views 900,000 +

Guess you like

Origin blog.csdn.net/zzti_erlie/article/details/104612429