通过web控制当前的SpringBoot程序重新启动
作者:qq_53985858
本文主要给大家介绍了如何通过web控制当前的SpringBoot程序重新启动,文章给出了详细的代码示例供大家参考,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
首先导入devtools依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>在controller中如下:
@RestController
public class RestartController {
@Autowired
ApplicationContext applicationContext;
@RequestMapping("/restart")
public String restart() {
Restarter restarter = Restarter.getInstance();
restarter.restart(new FailureHandler() {
public Outcome handle(Throwable failure) {
System.out.println("当前系统出现问题,无法重启项目...........");
return Outcome.ABORT;
}
});
return "重启服务成功!";
}
}启动类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication application = new SpringApplicationBuilder(Application.class).build(args);
application.run();
}
}
以上就是通过web控制当前的SpringBoot程序重新启动的详细内容,更多关于web控制SpringBoot重新启动的资料请关注脚本之家其它相关文章!
