Spring Boot2 热部署

成功的关键在于相信自己有成功的能力。

Eclipse OpenExplorer插件

Spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用。

具体应用:

首先,在pom.xml中添加依赖:

org.springframework.boot spring-boot-devtools true true org.springframework.boot spring-boot-maven-plugin true

Eclipse设置项目自动编译:

示例

这样就完成了热部署的配置,启动项目,此时如果再改文件,则项目就会自动重启。

踩过的坑:

第一次配置的时候maven镜像也是用的默认的(国外的),可能是这个原因,导致我spring-boot-devtools.jar下载的有问题,所以每次启动项目的时候devtools.jar加载失败,导致热部署不起作用。进入本地仓库手工删除spring-boot-devtools然后重新下载,热部署就起作用了。

所以,也建议大家maven镜像还是用国内的,比较好的阿里云Maven镜像,在settings.xml中添加:

alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central

关注以下,更多精彩等着你