IDEA环境下使用devtools实现热加载与热部署实现修改代码不需重启

1.引入devtools的maven依赖

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

2.在 plugin 中配置另外一个属性 fork,并且配置为 true。

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

3.设置IDEA

运行时编译配置:组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running” 。

解决idea debug模式下修改代码却不能生效

4.自动化编译配置:

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

解决idea debug模式下修改代码却不能生效

5. 进行一下application.properties配置

在有些版本我们需要配置热加载生效的开关,使其值等于true。下文是properties格式配置,喜欢yml格式的同学可以自行调整一下


#热加载生效
spring.devtools.restart.enabled=true
#额外新增的热加载目录
spring.devtools.restart.additional-paths= src/main/java
#热加载排除目录
#spring.devtools.restart.exclude= 

参考

手把手教你学Spring Boot 2.X

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2021-12-13
  • 2021-04-14
  • 2021-07-30
  • 2021-04-12
  • 2021-07-20
  • 2021-10-25
猜你喜欢
  • 2021-10-12
  • 2021-05-29
  • 2022-12-23
  • 2021-08-27
  • 2021-09-10
  • 2021-06-24
相关资源
相似解决方案