针对修改类时必须再次重新运行应用,对于开发者来说非常不方便。SpringBoot提供了spring-boot-devtools,它能在修改类或者配置文件时候自动重新加载SpringBoot应用。
SpringBoot添加热部署步骤:
1.需要打来pom文件,添加以下依赖:
注:在eclipse工具下还需要在project 中添加 spring-boot-maven-plugin,,idea中不需要添加此配置。
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build>
2.如果你使用的事idea,还需要到File->Setting->Build,…->Compiler 将右侧project automatically勾上
3.在idea中使用快捷键ALT+CTRL+A,搜素Registry
找到compiler.automake.allow.when.app.running,勾上开启此功能即可
至此热部署已经添加完毕,下面就开始使用。
重启应用,将改为后发现程序自动运行,说明热部署已经成功。