Author’s environment and version

JDK: 1.8.0_271(important) Spring: 5.2.4.RELEASE Download the Spring source code from the official Github library (github.com/spring-proj…) Download. It must be slow as it has to be downloaded from abroad, hahaha. However, we can log in to Gitee, import the project into Gitee, and the download will be much faster.

Enter Spring’s Github repository address in the text box

After the import is complete, click on Master and you can see that it contains many historical branch versions of Spring

Switch to the TAB bar and you can see various smaller versions

Look at the version of Spring and find the gradle.properties file

Look at Grandl and go to Spring-Framework /gradle/wrapper/gradle-wrapper.properties

Configure the mirror

After downloading the source code to the local, don’t rush to open with IDEA, configure ali cloud image first.Open the build.gradle file and find the Repositories TABAdd to it

 maven() { url "http://maven.aliyun.com/nexus/content/groups/public/" }
Copy the code

Then use idea to import the Spring-Framework project. Idea automatically downloads gradle dependencies. The Internet speed takes care of the rest.

pit

1. JDK version problems

My previous JDK version was 1.8.0_221, and then I re-installed the JDK and changed it to 1.8.0_271

2. Mirror problems

: Could not resolve: com. IBM. Websphere: uow: 6.0.2.17, that is because I will be the mirror to comment out the Spring.

3. Jar can’t be downloaded

This problem is very good to solve, direct Ctrl + C jar package address, in the browser for download. After the download is complete, need to find the gradle default to save the repository path, File – > Settings – > Build, Execution, Deployment – > Build Tools – > gradle. The default is inC:\Users\Administrator\.gradle Then go to caches\modules\files-2.1 under the. Gradle directory and copy the downloaded JAR into it. Example: Missing org.python: Jython-standalone :2.7.1You need to create the corresponding directory under files-2.1. A colon is a delimiter.

After solving all the above problems, Spring compiled successfully!!

Add the module

Next I take you to create your own module in Spring-Framework to see if you can use the source codeSelect Gradle to create a Java projectGive the module a nameIn the build.gradle file of the newly created Module, we add the spring-context dependency, which is equivalent to pom.xml in Maven:

dependencies {
    compile(project(":spring-context"))
}
Copy the code

After adding dependencies, let’s write a simple test class to try it out. First create a User class:

public class User { private Integer id; private String name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "User{" + "id=" + id + ", name='" + name + '\'' + '}'; }}Copy the code

Then create beans.xml in the Resources directory and configure the Bean:

<? The XML version = "1.0" encoding = "utf-8"? > <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="com.gongj.User" id="user"> <property name="id" value="1"/> <property name="name" value="ssss"/> </bean> </beans>Copy the code

Finally, write the main method:

public class Main { public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:beans.xml"); User user = ctx.getBean(User.class); System.out.println("user = " + user); }}Copy the code

Three more problems encountered during boot (I ** too hard ┭┮﹏┭┮)

Error 1:

Running the Build task in Spring-Core produces the missing JAR package

Error 2:

Step 1:

Step 2:

You need to select the main package of Spring-Core

Step 3: Add the JAR

Depending on the version, the jar may be in a different directory. Possibly under spring-core-Coroutines package. This package is the same as Spring-core.

Step 4: Then recompile the project.

Mistake 3:

Open the spring-context.gradle file and change the optional to compileThen run the main method again:

user = User{id=1, name='ssss'}
Copy the code