环境准备:
- IDE集成开发环境,IntelliJ IDEA(推荐)或Eclipse等
- JDK1.8(及以上版本)
- Apache-Maven 3.X
IntelliJ IDEA搭建方式:
-
方式一:使用Maven创建Spring Boot项目
-
创建Maven项目
-
在pom.xml文件中添加Spring Boot相关依赖
<!-- 引入Spring Boot依赖 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.3.RELEASE</version> </parent> <dependencies> <!-- 引入Web场景依赖启动器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
-
编写主程序启动类
@SpringBootApplication public class TestDemoApplication { public static void main(String[] args){ SpringApplication.run(TestDemoApplication.class,args); } }
-
创建一个用于Web访问的Controller
@RestController public class HelloController { @GetMapping("/hello") public String hello(){ return "hello Spring Boot"; } }
-
运行项目
启动项目,在浏览器上访问 http://localhost:8080/hello
-
-
方式二:使用Spring Initializr创建Spring Boot项目(推荐)
-
创建Spring Boot项目
-
创建一个用于Web访问的Controller
@RestController public class HelloController { @GetMapping("/hello") public String hello(){ return "hello Spring Boot"; } }
-
运行项目
启动项目,在浏览器上访问 http://localhost:8080/hello
-
Eclipse搭建方式:
-
方式一:使用Maven创建Spring Boot项目(推荐)
-
创建Maven项目
-
在pom.xml文件中添加Spring Boot相关依赖
<!-- 引入Spring Boot依赖 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.3.RELEASE</version> </parent> <dependencies> <!-- 引入Web场景依赖启动器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
-
创建resources文件夹和application.properties文件
-
编写主程序启动类
@SpringBootApplication public class TestDemoApplication { public static void main(String[] args){ SpringApplication.run(TestDemoApplication.class,args); } }
-
创建一个用于Web访问的Controller
@RestController public class HelloController { @GetMapping("/hello") public String hello(){ return "hello Spring Boot"; } }
-
运行项目
启动项目,在浏览器上访问 http://localhost:8080/hello
-
-
方式二:前往spring.io网站下载Demo导入
-
-
点击Generate Project下载项目压缩包
-
解压后,使用eclipse,Import -> Existing Maven Projects -> Next ->选择解压后的文件夹-> Finsh,OK done!
-
-
方式三:安装STS插件(不推荐,由于下载非常慢且容易下载失败)
-
安装插件,安装完成后重启eclipse生效
-
新建spring boot项目
-
总结:(个人建议)
- 推荐使用IntelliJ IDEA搭建方式中的Spring Initializr创建Spring Boot项目
- 推荐学习Spring Boot学习过程使用IntelliJ IDEA
- 还有别的问题可以在下方评论,我会逐一回复,感谢大家的阅读
文章评论