专业的编程技术博客社区

网站首页 > 博客文章 正文

SpringCloud在idea环境热部署微服务开发

baijin 2024-09-18 12:03:56 博客文章 3 ℃ 0 评论

在开发过程中,每修改代码会比较频繁启动、停止微服务动作,如果是热部署速度比手动停止后再启动更快,并且可以提高开发效率一定程度上专心敲代码。

热部署开发实现步骤

1、在微服务模块pom.xml添加 maven 引用包

<!-- SpringBoot自带热加载开发工具 -->
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-devtools</artifactId>
 <scope>runtime</scope>
</dependency>
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-configuration-processor</artifactId>
 <optional>true</optional>
</dependency>
<dependency>
 <groupId>joda-time</groupId>
 <artifactId>joda-time</artifactId>
 <version>2.3</version>
</dependency>

2、设置 idea 属性

“File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically” 。

组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running” 。

3、Chrome禁用缓存

F12(或Ctrl+Shift+J或Ctrl+Shift+I)--> NetWork --> Disable Cache(while DevTools is open)

至此,在idea中修改代码,修改后可以及时看到效果,无须手动重启和清除浏览器缓存。

测试方法

1.修改代码类-->保存:应用会重启

2.修改配置文件-->保存:应用会重启

3.修改页面-->保存:应用会重启,页面会刷新(需在yml文件中将spring.thymeleaf.cache设为false

不能使用分析

1.对应的spring-boot版本是否正确。

2.Intellij IDEA是否开启了Make Project Automatically。

3.是否加入plugin了,以及属性<fork>true</fork>。

4.如果设置SpringApplication.setRegisterShutdownHook(false),则自动重启将不起作用。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表