【英文】通过STS创建SpringBoot项目

Introduction

Creating a SpringBoot project based on SpringToolSuite4.

Preparation

  • Java 1.8
  • Maven 3.6.3

Configuring Maven in STS

  • Spring Tool Suite 4->Preferences->Maven->Installations->Add

  • Configure the Maven installation directory

  • Select the new configuration->Apply

  • Maven->User Settings->Modify the configuration->Apply

Creating a Project using Official Starter

  • File->New->Spring Starter Project

  • Configure project parameters->Next

  • Select SpringBoot version->Finish

Creating a Project using Alibaba Cloud’s Starter

  • File->New->Spring Starter Project

  • Configure project parameters, change Server URL to Alibaba Cloud’s Starter->Next

  • If the version is displayed incorrectly, you can manually adjust the version, ignore the version number in the configuration version, and select Next

  • Manually adjust the version number->Finish

Importing Project using Packaged File from Official Website

  • Configure project parameters on the official website and download the packaged new project https://start.spring.io

SNAPSHOT: Snapshot version
M2: Important feature release version, not official

  • Unzip the package and import the project into STS

  • File->Import->Maven->Existing Maven Projects->Next

  • Select the project root directory->Finish

Creating Project using Normal Maven Project

  • Create a simple Maven project

  • File->New->Other->Maven->Maven Project->Select Simple Maven Project->Next

  • Configure project parameters->Finish

  • Replace the content of the pom.xml file with:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.company</groupId>
<artifactId>CGB-SPRINGBOOT-04</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CGB-SPRINGBOOT-01</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

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

</project>
  • Right-click on the project->Maven->Update Project

  • Select Force Update of Snapshots/Releases->OK

  • Create the entry program manually

  • Create a new Java file with the fully qualified name com.company.CgbSpringboot04Application

  • Define the annotation @SpringBootApplication on the class and define the main method

1
2
3
4
5
6
7
8
@SpringBootApplication
public class CgbSpringboot04Application {

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

}

Copying Project from Another Machine

  • After building a complete new project using any of the above methods, compress the project and copy it to another machine

  • Adjust the parameters in the pom.xml file

Completion