1 introduction
This is the first article in the SpringBoot2.1 source analysis series, which focuses on how to set up our source code reading and debugging environment. If experienced friends can skip this article.
2 Environment Installation requirements
- IntelliJ IDEA
- JDK1.8
- Maven3.5 above
Download the SpringBoot source project from Github
Start by providing the Github address for SpringBoot2.1.0: github.com/spring-proj…
Since we need to read the source code and analyze the source code project, we need to write some comments in it to help us read and understand the source code, so we need to fork the SpringBoot source project into our github repository. Then use git clone url command has been forked to github repository of SpringBoot source to pull down. However, because the above method is often slow and usually times out, the author directly downloads the SpringBoot project and then imports IDEA.
4 Import the SpringBoot source project to IDEA
Import the spring-boot2.1.0.release project into IDEA using Maven mode, and then proceed to next to complete the import. Note that the JDK version is 1.8 and Maven version is 3.5+.
Maven dependencies can take a long time to download. If You don’t have maven repositories configured, you can download them faster. referenceConfigure Maven to use the (A-li-cloud) repositoryConfigure it.
5 Compile and build the SpringBoot source project
After importing the project, we compile and build the SpringBoot source project. Before building, we do two configurations:
- To disable Code checking for Maven, add a configuration to the root pom.xml, as shown below:
- The project tag of your pom.xml file may be displayed
java.lang.OutOfMemoryError
Error, this is because the maximum heap memory of JVM set by Maven importer in IDEA is too small, as shown in the following figure, please refer to it at this timeMaven package import error (IntelliJ IDEA)Solve it.
After the above two configurations, we can now directly execute the following Maven commands to compile and build the source project.
mvn clean install -DskipTests -Pfast
Copy the code
At this time, there is a long wait. I wait about 5 minutes and it shows that the build is successful, as shown in the picture below:
6 Run the Sample delivered with SpringBoot
Because the Spring-boot-samples module in the SpringBoot source code comes with many DEMO samples, we can use one of them to test and run the SpringBoot source project we just built. However, it was found that the spring-boot-samples module was gray, as shown below:This is because the spring-boot-samples module was not added to the root pom.xml, so just add it to the root pom.xml and add the following configuration, as shown below:At this point, we will select the spring-boot-sample-tomcat sample project under the spring-boot-samples module to test itSampleTomcatApplication
themain
Function, the successful startup interface is as follows:
Then we send an HTTP request in the browser. At this time, we can see that the server returns a successful response, indicating that the SpringBoot source environment has been built successfully. Next, we can debug, as shown in the following figure:
7. Hands-on practice
The front has successfully built SpringBoot source reading environment, friends remember to build a set of their own SpringBoot source debugging environment oh, reading source debugging is very important, hey hey.
Next section: how do we analyze SpringBoot source code involving modules and structures? –SpringBoot source code (2)