[Java]IDEA-SpringBoot-devtools热部署无效,终于成功。。

正常流程:

1、在pom.xml文件中添加devtools依赖

在pom.xml文件中的<dependencies>中添加以下代码:

<!-- 热部署devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <!-- optional=true,依赖不会往下传递,如果有项目依赖本项目,并且想要使用devtools,需要重新引入 -->
            <optional>true</optional><!--这个必须要有的-->
            
            <version>2.0.4.RELEASE</version><!--版本号可以不写-->
            <scope>true</scope><!--这个也可以不谢-->
        </dependency>

2、在pom.xml文件中添加fork配置

在pom.xml文件中的<build> <plugins> <plugin>中添加以下代码:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

                <!--这下边的才是要添加的内容-->
                <configuration>
                    <!-- 增加fork 才允许热部署 ,fork 交叉-->
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>


            </plugin>
        </plugins>
    </build>

3、设置IDEA自动编译

3.1、在File | Settings | Build, Execution, Deployment | Compiler下勾选Build project automatically。点击ok,关闭

3.2、在项目中按Ctrl + Shift + Alt + / ,选择Registry...,勾选complier.automake.allow.when...选项,最后close

 

 

 

如果热部署不成功,几种解决方案:

1、修改pom.xml中devtools依赖的版本号2.0.4.RELEASE为其他版本,例如1.5.7.RELEASE

2、CTRL + SHIFT + A –> 查找make project automatically –> 选中

3、点击Edit... -》将运行Application文件修改成update classes and resources

4、在Google页面按F12进入开发者界面,进入setting,将network的Disable cache勾选

5、(未测试)重启IDEA

6、(未测试)在debug模式下运行,不直接run。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值