Analysis of idea importing spring boot source code process

Write in front

surroundings

win10(其他应该也可),
idea2020-2(最好保持一致),
jdk8+,
maven3.5.4(最好保持一致)

other

It's best to prepare circumvention software, because it may not be downloaded due to partial reliance.

1: Download the source code

Fork the code from here to your own warehouse. The purpose of fork is to directly modify the source code. If you find that downloading the code from git is too slow, you can also import the code into gitlab and then download it. You can refer to the following pictures for the approximate process of importing into gitlab:
Insert picture description here
Insert picture description here
After the completion, you can git clonecode.

2: Compile

2.1: Switch branches

Here we use tag:v2.1.14.RELEASEto operate, command format git checkout -b <自定义本地分支名称> <远程分支名称>. The following command creates a corresponding branch locally:
git checkout -b v2.1.14.RELEASE-local v2.1.14.RELEASE.

2.2: Configure maven3.5.4

Mainly add Ali source, as follows:

<mirror>
  <id>alimaven</id>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  <mirrorOf>central</mirrorOf>
</mirror>
<mirror>
  <id>alimaven</id>
  <mirrorOf>central</mirrorOf>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

2.3: Download dependencies

/paht/to/your3.5.4/mvn clean install -DskipTests -Pfast

If it fails, try a few more times. I also tried a few times before it succeeded. The last BUILD SUCCESSthing you see is success.

2.4: Solve formatting problems

/paht/to/your3.5.4/mvn spring-javaformat:apply

I didn't encounter any problems in this step. If I encounter problems, I will try a few more times.

2.5: Convert to idea project

/paht/to/your3.5.4/mvn idea:idea

2.6: Import to idea

Simply select the project and import it. Whether the verification is successful can be verified by executing the org.springframework.boot.tests.hibernate52.Hibernate52Applicationclass. If the execution is successful, the import is complete.

2.7: Turn off format detection

Add the following content to the root pom.xml:

<properties>
	<revision>2.1.14.RELEASE</revision>
	<main.basedir>${basedir}</main.basedir>
	<disable.checks>true</disable.checks> // 新添加的
</properties>

The final idea effect is as follows:
Insert picture description here

3: Create an MVC project

The project is carried out spring-boot-testsby creating submodules in it.

3.1: Create a pom project spring-boot-dongshidaddy-tests

Select the mouse spring-boot-testsand new-modulepay attention to the selection maven, as shown in the following figure:
Insert picture description here
delete after creation src, only keep the pom.xml file. In the end, my pom.xml is as follows, because the input gav information is not the same, so it may not be exactly the same, just for reference:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<artifactId>spring-boot-dongshidaddy-tests</artifactId>
		<groupId>org.springframework.boot</groupId>
<!--		<version>2.1.14.RELEASE</version>-->
		<version>${revision}</version>
<!--		<relativePath>../../pom.xml</relativePath>-->
	</parent>

	<artifactId>spring-boot-dongshidaddy-mvc-tests</artifactId>
	<name>Spring Boot Yunai DONGSHIDADDY tests</name>
	<description>测试springboot源码导入项目</description>

	<properties>
		<main.basedir>${basedir}/../../..</main.basedir>
	</properties>

	<dependencies>
		<!-- Compile -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

3.2: Create a pom project spring-boot-dongshidaddy-tests

The method is the same spring-boot-dongshidaddy-tests, but pay attention to keep it src, and the final figure is as follows: The
Insert picture description here
pom is finally as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<artifactId>spring-boot-dongshidaddy-tests</artifactId>
		<groupId>org.springframework.boot</groupId>
<!--		<version>2.1.14.RELEASE</version>-->
		<version>${revision}</version>
<!--		<relativePath>../../pom.xml</relativePath>-->
	</parent>

	<artifactId>spring-boot-dongshidaddy-mvc-tests</artifactId>
	<name>Spring Boot Yunai DONGSHIDADDY tests</name>
	<description>测试springboot源码导入项目</description>

	<properties>
		<main.basedir>${basedir}/../../..</main.basedir>
	</properties>

	<dependencies>
		<!-- Compile -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

3.3: Create the main startup class

@SpringBootApplication
public class MyMvcApplication {
    
    

	public static void main(String[] args) {
    
    
		SpringApplication.run(MyMvcApplication.class, args);
	}
}

3.4: Create a controller

@Controller
@RequestMapping("/mydemo")
public class MyDemoController {
    
    

	@ResponseBody
	@RequestMapping("/hello")
	public String hello() {
    
    
		return "hi from dongshidaddy!";
	}
}

3.5: Start test

$ curl --silent http://localhost:8080/mydemo/hello
hi from dongshidaddy!

Finally: get out of the way, I want to drink Luckin

Insert picture description here

Guess you like

Origin blog.csdn.net/wang0907/article/details/109840166