spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用。
具体应用:
首先,在pom.xml中添加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
Eclipse设置项目自动编译:
这样就完成了热部署的配置,启动项目,此时如果再改文件,则项目就会自动重启。
踩过的坑:
第一次配置的时候maven镜像也是用的默认的(国外的),可能是这个原因,导致我spring-boot-devtools.jar下载的有问题,所以每次启动项目的时候devtools.jar加载失败,导致热部署不起作用。进入本地仓库手工删除spring-boot-devtools然后重新下载,热部署就起作用了。
所以,也建议大家maven镜像还是用国内的,比较好的阿里云Maven镜像,在settings.xml中添加:
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
配置文件在maven安装目录在conf下