Mac环境中配置Spring Boot项目热部署

引入devtools依赖

在pom文件中引入devtools依赖:

        <!-- 配置Spring Boot热部署依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>

同时需要在spring-boot-maven-plugin插件中进行如下的配置:

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 实现热部署的设置 -->
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>

设置Spring Boot项目更新策略

在项目启动项中进行如下更新策略的设置:

设置IDEA的项目自动编译

Mac中使用"Command+,"快捷键打开系统Preference设置,设置自动编译:

设置IDEA Registry

Mac环境下使用Command+Shift+A的快捷键,输入Registry,选择第一个(下图的红框有点问题)。

 

然后进行找到如下的第一个配置,进行勾选:

  • compiler.automake.allow.when.app.running:设置自动编译
  • compiler.document.save.trigger.delay:设置自动更新文件的时延(这里使用默认值,也可以进行修改)
  • compiler.automake.trigger.delay:设置自动编译的时延(这里使用默认值,也可以进行修改)

在Chrome浏览器中设置不使用缓存

在浏览器的Network选项下,勾选Disable cache:

完成如上的设置,即可以在Mac环境下IDEA中实现Spring Boot项目的自动热部署,在修改页面后不需要重新项目即可生效。

发布了296 篇原创文章 · 获赞 35 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/yitian_z/article/details/104113379