共计 2514 个字符,预计需要花费 7 分钟才能阅读完成。
1、使用 Spring Initializr 创建 Spring Boot 应用
1.1、点击 Create New Project
1.2、选中 Spring Initializr
1.3、填写 Project Metadata
1.4、选择项目依赖
1.5、创建完成
2、目录结构
2.1、Maven Wrapper 文件
Maven Wrapper 文件包括.mvn 目录、执行 mvnw 和 mvnw.cmd, 这些文件均源于 GitHub 工程。
2.2、FirstSpringbootApplication 文件
// 此类是 Spring Boot 应用的启动类 | |
public class FirstSpringbootApplication {public static void main(String[] args) {SpringApplication.run(FirstSpringbootApplication.class, args); | |
} | |
} |
2.3、application.properties 文件
application.properties 是 Spring Boot 默认的应用外部配置文件, 其配置属性可以控制 Spring Boot 应用的行为,如调整 Web 服务端口等。
2.4、Spring Boot 应用 JUnit 测试文件
在 test 目录下有一个 FirstSpringbootApplicationTests.java 文件, 代码如下:
class FirstSpringbootApplicationTests { | |
void contextLoads() {}} |
此文件为 Spring Boot 应用的 JUnit 测试文件, 与其引导 的 Java 文件对应。
2.5、.gitignore 文件
内容如下:
HELP.md | |
target/ | |
!.mvn/wrapper/maven-wrapper.jar | |
!**/src/main/** | |
!**/src/test/** | |
### STS ### | |
.apt_generated | |
.classpath | |
.factorypath | |
.project | |
.settings | |
.springBeans | |
.sts4-cache | |
### IntelliJ IDEA ### | |
.idea | |
*.iws | |
*.iml | |
*.ipr | |
### NetBeans ### | |
/nbproject/private/ | |
/nbbuild/ | |
/dist/ | |
/nbdist/ | |
/.nb-gradle/ | |
build/ | |
### VS Code ### | |
.vscode/ |
它定义了最常见的文件或目录的版本控制忽略名单, 包括基于 Eclipse 的 STS、IDEA 和 NetBeans 等项目元信息资源
2.6、mvnw 和 mvnw.cmd
mvnw 或 mvnw.cmd 脚本相当于 mvn 命令。引导 .mvn/wrapper/maven-wrapper.jar 下载 Maven 二进制文件,前者用于 *nix 平台, 后者工作于 Windows 操作系统。
2.7、pom.xml 文件
此文件是 Spring Boot 应用的 jar 包依赖文件,内容如下:
<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.6.RELEASE</version> | |
<relativePath/> <!-- lookup parent from repository --> | |
</parent> | |
<groupId>com.tyschool</groupId> | |
<artifactId>first-springboot</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<name>first-springboot</name> | |
<description>Demo project for Spring Boot</description> | |
<properties> | |
<java.version>1.9</java.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</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> |
正文完
星哥玩云-微信公众号
