创建 Spring Boot 项目
开发环境配置完成后,接下来,我们就可以通过 Intellij IDEA 创建一个 Spring Boot 项目了。
Intellij IDEA 一般可以通过两种方式创建 Spring Boot 项目:
使用 Maven 创建
使用 Spring Initializr 创建
使用 Maven 创建
1. 使用 IntelliJ IDEA 创建一个名称为 helloworld 的 Maven 项目,创建过程请参考 IDEA 新建 Maven 项目。
2. 在该 Maven 项目的 pom.xml 中添加以下配置,导入 Spring Boot 相关的依赖。
... org.springframework.boot spring-boot-starter-parent 2.4.5 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test ...
3. 在 net.biancheng.www 包下,创建一个名为 helloWorldApplication 主程序,用来启动 Spring Boot 应用,代码如下。
纯文本复制
package net.biancheng.www;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class helloWorldApplication { public static void main(String[] args) { SpringApplication.run(helloWorldApplication.class, args); }}