开始动手
-
选择构建工具、编程语言、SpringBoot版本;
输入Group和Artifact
选择所依赖的组件(建议选择Web)
-
点击生成按钮,解压后导入到IDE中
这里演示导入eclipse(neon.3 jee版本)中
使用的是maven构建工具,导入时需注意是导入一个maven项目
基本启动
-
配置
在/src/main/resources/application.properties 文件中添加一些基础配置
server.port=8989 server.context-path=/
默认为 8080
-
编写Controller
package morning.cat.study.springboot.hotdeploy.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping(value = "/hi", method = { RequestMethod.GET, RequestMethod.POST }) public String method1(@RequestParam(value = "name", defaultValue = "morningcat") String name) { return "Hello " + name; } @GetMapping(value = "/hi/{userName}") public String method2(@PathVariable String userName) { return "Hello " + userName; } }
-
启动
运行 SpringbootHotdeployApplication 类
-
测试
在浏览器输入 http://localhost:8989/hi
若出现 Hello morningcat 则成功
即可完成热部署
热部署
-
添加依赖
在 pom.xml 添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
重新启动即可
实践demo
实践代码 : https://gitee.com/mengzhang6/springboot-hotdeploy