【SpringBoot框架】起步-通过Intellij idea搭建Spring Boot的Reactive Web应用
第一步:打开Intellij Idea工具并进入File - New - Project,选择Spring initializr项。
如果Spring Initializr项没有找到,可以通过File - Settings - Plugins的Installed中查找下有没有Spring Boot这个插件的安装后的状态,如果没有启用,勾选启用就解决了;如果没有安装可以通过Marketplace选项卡中搜索并安装解决。
第二步:通过以上默认设置,点击next进入项目的结构信息的配置页。
第三步:设置完成后,点击next进入应用依赖包的选择页。
这里只选择了最基础的Developer Tools下的Lombok包和Web下的Spring Reactive Web包。
第四步:选择完成后,点击Next进入项目位置的设置页,设置完成后点击Finish完成项目的初始化。
通过以上配置Intellij Idea会自动生成项目的核心文件,进入项目工作空间后,可能需要配置Maven的相关配置,可以进入File - Settings - Maven。
项目的结构如下:
第五步:新建HelloController类,验证搭建结果。
package com.example.demo; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono; @RestController @RequestMapping(value = "/demo/", method = RequestMethod.GET) public class HelloController { @GetMapping("hello") public Mono<String> mono() { return Mono.just("hello world"); } }
第六步:右键DemoApplication启动类,运行项目。
启动完成后,浏览器输入http://localhost:8080/demo/hello,验证结果。