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
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
finally succeeded
The establishment of sub-module source code debugging
File-> New-> Module
GroupId-> org.springframework
Version-> 5.0.17.BUILD-SNAPSHOT (gradle.properties may know from the project file)
- Delete the files in the module build settings.gradle
- After settings.gradle under the spring items plus the following sentence include (whose name I built module) "learning-spring"
- 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