SpringBoot实现热部署

SpringBoot热部署的操作

前言

在实际开发工程中,每次修改代码都得将项目手动重启,手动部署,需要花费大量的时间吗。对于我来说,手动重启过程实在难受。以此我们将Spring项目配置热部署来自动重启。



步骤一:在pom.xml加入

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
            <scope>true</scope>
        </dependency>
     <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>




步骤二:在application.yml加入以下代码

spring:
  thymeleaf:
    cache: false
  devtools:
    restart:
      enabled: true #开启热部署
      additional-paths: src/main/java #重启目录
  freemarker:
    cache: false  #页面不加载缓存,修改即时生效






步骤三:修改idea里面的设置

在这里插入图片描述
开启划红线的地方






我这里是Eclipse的设置(Ctrl+Alt+T)打开Actions搜索
在这里插入图片描述
默认的是采用的idea的快捷键 ctrl + shift + alt + / ,选择Registry,勾上 Compiler autoMake allow when app running

在这里插入图片描述
打开Registy选项开启 compiler.automake.allow.when.app.running







步骤四:打开Run/Debug Configurations

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
添加spring-boot:run命令行



步骤五:运行

在这里插入图片描述
点击Run



测试结果

 @GetMapping("/hello")
    public String hello(@RequestParam(value = "name",defaultValue = "World")String name){

        return String.format("Hello %s!",name);
    }

加入一段代码

 System.out.println("热部署测试");

发现控制台在自动打印在这里插入图片描述
如果有这一行代码代码开启热部署成功

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值