0.声明

  缘由:没有学过或者没有经历SpringBoot的Application运行机制的话,一定会好奇,博主为啥会写一篇关闭开启的博文,是不是好幼稚?(/o(╥﹏╥)o),待我娓娓道来......为什么需要关闭Application?因为它每运行一次就占用一个端口啊!!!!(殊不知,在关闭不掉这端口的时候是多痛苦) 待下一次应用再次调试启动时,就端口冲突了....而Application开启后又极其难关闭,用任务管理器是杀不死这个Web Application小强的。在此之前,只能通过关闭IDE的方式关闭,而查询网友文献,均没有具体说清楚具体如何操作,都是把文章抄过来抄过去,连一个字都没有变,这怕也是国内知识(保护意识不强,版权意识不强所导致的)抄袭成风的劣根性吧!!!!!!

  引用文献

    springboot项目的优雅关闭方式:https://blog.csdn.net/XlxfyzsFdblj/article/details/82054744

  环境

    Eclipse+Chrome+Postman(网络请求调试的Chrome插件)

1.开启运行Application测试类【主流/推荐】

package com.edu.xhu.jobspider.examples.controller;

/**
* SpringBoot Web测试运行类
* @author Johnny Zen
* @createTime 2018年9月24日
* @description 创建步骤:
* 1.先创建maven web项目
* 2.继承parent,增加springboot-web依赖,配置打包标签
* 3.配置application.yml
* 4.创建运行文件App.java
* 5.用java -jar 文件.jar 进行运行
*/ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @EnableAutoConfiguration
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@RestController
@RequestMapping("/demo01")
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
} @RequestMapping("/hello")
public String hello(){
return "hello-SpringBootApp!!";
}
}

Step1:Eclipse:[App.Java]>右键>Run As>Java Application

Step2:Chrome:http://localhost:8080/demo/demo01/hello

2.安全关闭Application

【不推荐方法】关闭正在开发环境的IDE(Eg:Eclipse)

【推荐方法】

Step1:Maven中添加依赖项

		<!-- actuator(为关闭application) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Step2:Application.yml增加配置

# 关闭Application
endpoints:
shutdown:
enabled: true #启用shutdown
sensitive: false #禁用密码验证  

Step3:Postman 运行shutdown命令请求:http://localhost:8080/demo/shutdown

最新文章

  1. 认识Android Service
  2. 使用C#程序处理PowerPoint文件中的字符串
  3. 如何向github上传文件
  4. PHP代码规范
  5. 终端改变host的类型,还原
  6. DSP using Matlab 书内练习Example 2.1
  7. Python开发【程序】:计算器
  8. 关于Cocoapods安装与问题
  9. nodejs中package.json文件模块依赖的版本格式
  10. Mysql show Status参数详解
  11. 分享一个通用的分页SQL
  12. hdu1573-X问题
  13. XLSTransformer生成excel一个简单的演示示例文件
  14. Redis配置成系统服务(CentOS7)
  15. java学习笔记 --- 多态
  16. 实现一个网易云音乐的 BottomSheetDialog
  17. 【bzoj1045】【HAOI2008】 糖果传递
  18. R语言数据集的技术
  19. docker pull报错failed to register layer: Error processing tar file(exit status 1): open permission denied
  20. spark DataFrame

热门文章

  1. 利用XShell上传、下载文件(使用sz与rz命令)
  2. iframe 自适应
  3. SpringBoot开发案例之拦截器注入Bean
  4. 控制结构(5): 必经之地(using)
  5. MySQL 8.0.x for Windows 解压缩版配置安装
  6. Unit 6.标准文档流,浮动,清除浮动以及margin塌陷问题
  7. AI佳作解读系列(一)——深度学习模型训练痛点及解决方法
  8. Flutter之CustomView
  9. sql 书写 规范 优化
  10. C. Multi-Subject Competition 思维+前缀和+填表加减复杂度(复杂度计算错误)