我们在开发中反复修改类、页面等资源,每次修改后都是需要重新启动才生效,这样每次启动都很麻烦,浪费了大量的时间。 能不能在我修改代码后不重启就能生效呢?可以,由于Spring Boot应用只是普通的Java应用,所以JVM热交换(hot-swapping)也能开箱即用。不过JVM热交换能替换的字节码有限制,想要更彻底的解决方案可以使用Spring Loaded项目或JRebel。 spring-boot-devtools 模块也支持应用快速重启(restart),即实现“热部署”。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
选择【File】→【Settings】选项,打开Compiler面板设置页。目的:设置为自动编译
在项目任意界面中,使用快捷键“Ctrl+Shift+Alt+/”打开Maintenance选项框,选中并打开Registry页面。 目的:指定IDEA工具在程序运行过程中自动编译
启动chapter01项目,通过浏览器访问http://localhost:8080/hello
修改类页面请求控制类(例:hellocontroller)中的请求处理方法hello()的返回值,刷新浏览器。