Reference: juejin. Cn/post / 684790…
Local environment to obtain the springframework source code method
Local JDK: 11.0.6 Gradle(5.6.3) : C:\LagouDujin\gradle-5.6.3-bin.zip
1. Use git to obtain the source code of springframework
1.1. Create a folder in any disk path and name it as you like. SpringFramWork is recommended
For example: C: \ LagouDujin \ SpringFramWork
1.2. Go to the SpringFramWork folder, open the git command line, and type the following command
git clone https://github.com/spring-projects/spring-framework.git
Copy the code
1.3. Switch the code to Origin /5.1.x
Git checkout origin / 5.1 xCopy the code
2. Add an Ali Cloud image
In the process of compiling, Spring will automatically download some dependent packages. By default, we will use the official image, which is slow to download. Therefore, we will add the domestic image in the first place, paste the following code into the build.gradle file under the repository node.
/ / add ali cloud image maven {url "http://maven.aliyun.com/nexus/content/groups/public"}Copy the code
Gradle-4.10.3-bin.zip is not JDK 11.0.6 compatible with gradle-4.10.3-bin.zip in gradle-4.10.3-bin.zip
3.1. Contents of errors reported:
Found invalid Gradle JVM configuration: JDK 11.0.6 isn't compatible with Gradle 4.10.3. Please fix JAVA_HOME environment variable.
Copy the code
3.2. Configuring object Files:
C:\LagouDujin\SpringFramWork\spring-framework\gradle\wrapper\gradle-wrapper.properties
Copy the code
3.2.1. Modification required:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
Copy the code
3.2.2. Configuration Contents:
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists # distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip DistributionUrl = file \ : \ / / / C: / LagouDujin/gradle - 5.6.3 - bin. Zip zipStoreBase = GRADLE_USER_HOME zipStorePath = wrapper/distsCopy the code
3. Import the project
C:\LagouDujin\SpringFramWork\spring-framework
4. After the project is imported, execute the following compilation (you can use the following command line compilation, or use the Gradle plugin in IDEA) :
4.1 compile spring – the core
gradlew :spring-core:compileTestJava
4.2 compile spring oxm. –
gradlew :spring-oxm:compileTestJava
4.3 compile spring – the context
gradlew :spring-context:compileTestJava
4.4 compile spring beans
gradlew :spring-beans:compileTestJava
4.5 compile spring – aspects
gradlew :spring-aspects:compileTestJava
4.6 compile spring aop
gradlew :spring-aop:compileTestJava
5. Create HelloWord program and analyze source code (for example: create SpringMVC HelloWord program and analyze SpringMVC source code)
5.1. Configuration files
C:\LagouDujin\SpringFramWork\spring-framework\spring-lagou-mvc\src\main\resources\springmvc.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd ">
<! -- Enable controller scan -->
<context:component-scan base-package="com.lagou.edu.controller"/>
<! Configure the view parser for SpringMvc -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<! Automatically register the most appropriate processor mapper, processor adapter (call handler method) -->
<! --<mvc:annotation-driven/>-->
</beans>
Copy the code
5.2 web. XML
C:\LagouDujin\SpringFramWork\spring-framework\spring-lagou-mvc\src\main\webapp\WEB-INF\web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Copy the code
5.3. The JSP file
C:\LagouDujin\SpringFramWork\spring-framework\spring-lagou-mvc\src\main\webapp\WEB-INF\jsp\success.jsp
<%@ page language="java" isELIgnored="false" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
</head>
<body>
<%System.out.println("Jump to page"); %> Jump successful! ${date} </body> </ HTML >Copy the code
5.4. Controller file (note form)
package com.lagou.edu.controller;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.FlashMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.support.RequestContextUtils;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
@Controller
@RequestMapping("/demo")
public class DemoController {
@RequestMapping("/handle01")
public String handle01(String name,Map<String,Object> model) {
System.out.println("++++++++handle01 processing....");
Date date = new Date();
model.put("date",date);
return "success"; }}Copy the code