springboot热部署
Springboot当发生了任何修改之后,必须关闭后再启动Application类才能够生效,显得略微麻烦。 其实Springboot提供了热部署的方式,当发现任何类发生了改变,马上通过JVM类加载的方式,加载最新的类到虚拟机中。 这样就不需要重新启动也能看到修改后的效果了
实现:
- 在pom.xml中新增加一个依赖和一个插件
依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency>
插件:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
重新启动Application,然后随便修改一下前端的页面, 刷新页面就会发现有了变化
可能遇到的问题:
上面的步骤做好后还是没效果
解决方法:
如果是idea,需要改以下两个地方:
1、勾上自动编译或者手动重新编译
File > Settings > Compiler > Make Project automaticall
2、用Ctrl+Shift+A打开全局搜索搜registry > 勾选Compiler autoMake allow when app running