1、在Maven的pom.xml文件中添加依赖 热部署
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>2、继续在Maven的pom.xml文件中添加插件的配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork><!-- 如果没有该配置,热部署的devtools不生效 --> </configuration> </plugin> <!-- 自定义配置spring Boot使用的JDK版本 --> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>如果是Eclipse,配置到这里,只要重启服务,热部署就会生效了。 但是IDEA的话,热部署还不会生效,因为devTools只会在类路径上的文件发生更改时才会自动重启,而IDEA默认不会自动编译。 解决方法有两种: 1、手动:修改完代码,按快捷键Ctrl+F9,手动构建项目,或者只修改单个类文件的话,按Ctrl+Shift+F9,重新编译该类文件,即可触发重启服务。
注意: 即使没用加devtools用上面这两个快捷键是可以解决编译不需要重启的问题的.
2、**自动**: 1)File -> Settings -> Compiler,勾选 Build Project automatically2)按快捷键Ctrl+Shift+Alt+/,选择1.Registry… 3)勾选 compiler.automake.allow.when.app.running 即可