SpringBoot - 热部署实践

开始动手

  1. 打开 SPRING INITIALIZR网址

  2. 选择构建工具、编程语言、SpringBoot版本;

    输入Group和Artifact

    选择所依赖的组件(建议选择Web)

  3. 点击生成按钮,解压后导入到IDE中

    这里演示导入eclipse(neon.3 jee版本)中

    使用的是maven构建工具,导入时需注意是导入一个maven项目

    快速构建Springboot项目

基本启动

  1. 配置

    在/src/main/resources/application.properties 文件中添加一些基础配置

    server.port=8989
    server.context-path=/
    

    默认为 8080

  2. 编写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;
        }
    
    }
    
    
  3. 启动

    运行 SpringbootHotdeployApplication 类

  4. 测试

    在浏览器输入 http://localhost:8989/hi

    若出现 Hello morningcat 则成功

    
    

    即可完成热部署

热部署

  1. 添加依赖

    在 pom.xml 添加依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    

    重新启动即可

实践demo

实践代码 : https://gitee.com/mengzhang6/springboot-hotdeploy

转载于:https://my.oschina.net/mengzhang6/blog/2046416

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值