Spring Boot 入门(一)搭建第一个Spring Boot程序
- maven构建项目
官网地址:https://start.spring.io/

Packaging:这里选择War包,方便Application启动应用
点击“GENERATE”按钮生成项目
- IntelliJ IDEA导入Project


“install”初始化项目,下载Maven包

- 新建一个Controller
新建文件夹controller,新建HelloWorldController
package com.example.demo.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { @RequestMapping("/hello") public String index() { return "Hello World"; } }

- 启动应用
打开DemoApplication,Run'DemoApplication.main()'

默认地址:http://localhost:8080/hello


发现启动应用失败,根pom修改下spring-boot-starter-tomcat的scope
SpringBoot项目中配置tomcat时scope的含义

再次启动成功


浙公网安备 33010602011771号