以下是创建简单的Spring Boot项目的步骤。
第1步:打开Spring initializr URL:https://start.spring.io 。
第2步:提供组和Artifact名称。这里输入的组名称为:com.xntutor
和Artifact
名称为:spring-boot-example
。
第3步:单击“生成/Generate”按钮。
当单击生成/Generate按钮时,它将开始将项目打包为.rar
文件并下载该项目。
第4步:提取RAR文件。
第5步:导入文件夹。
操作: File -> Import -> Existing Maven Project -> Next -> Browse -> Select the project -> Finish。
导入项目需要一些时间。 成功导入项目后,可以在Package Explorer中看到项目目录。 项目目录如下图所示:
文件:SpringBootExampleApplication.java
package com.xntutor.springbootexample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootExampleApplication.class, args);
}
}
文件:pom.xml
<?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.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xntutor</groupId>
<artifactId>spring-boot-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-example</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>
第6步:运行SpringBootExampleApplication.java文件。
右键单击文件->运行方式-> Java应用程序
应用程序成功运行结果如下: