spring-boot-devtools 可以动态编译java类。比如在开发过程中,修改了某个java类,但是重启需要好长时间,这个时候用devtools能很快编译好修改的java代码,实现热部署
使用:
pom依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--开发工具-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
启动类和接口:
@RestController
@EnableAutoConfiguration
public class HelloWorldApp {
@RequestMapping("/")
String home() {
return "Hello World";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(HelloWorldApp.class, args);
}
}
启动后访问 localhost:8080
Hello World
修改 home() 方法:
@RequestMapping("/")
String home() {
return "Hello World update";
}
在开发ide的菜单,点击Build->Recompile
重新编译,编译成功后,访问localhost:8080
Hello World update