springboot 通过代码自动生成pid的方法
作者:神易风 时间:2023-11-27 02:54:57
springboot项目部署
平时我们在部署springboot打成jar方式部署得时候,大多数都会编写启动脚本,脚本有很多种写法,但大多数意思都是一样的,java -jar 启动项目,获取进程pid保存到指定文件中。关闭程序时,获取进程pid kill -9 $pid。获取pid有很多种写法,简答粗暴netstat -nlp port | grep port | grep -v 。其实springboot本身就有更简单方式来处理这种问题,两行代码就搞定。
@SpringBootApplication
public class PidApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(PidApplication.class);
app.addListeners(new ApplicationPidFileWriter());
app.run(args);
}
}
启动项目后会在生成application.pid文件存放pid
如果你想存放指定目录在配置中添加spring.pid.file=/var/log/app.pid
即可是不是很简单啊
来源:https://www.jianshu.com/p/9a6f8a4d8968
标签:springboot,pid
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java 8中字符串拼接新姿势StringJoiner详解
2022-03-09 03:00:28
java list去重操作实现方式
2021-09-22 13:26:08
简介Java的Hibernate框架中的Session和持久化类
2023-04-17 14:41:13
详解利用spring-security解决CSRF问题
2023-07-31 14:31:19
java实现多个文件压缩成压缩包
2022-12-06 17:45:54
Java集合系列之ArrayList源码分析
2023-01-31 03:02:36
Android Button按钮的四种点击事件
2021-12-16 04:02:41
Java 实战项目锤炼之嘟嘟健身房管理系统的实现流程
2021-09-24 23:58:07
![](https://img.aspxhome.com/file/2023/0/125250_0s.png)
Git和Maven的子模块简单实践
2023-09-22 01:45:55
winform C#获得Mac地址,IP地址,子网掩码,默认网关的实例
2021-06-28 20:45:50
![](https://img.aspxhome.com/file/2023/5/98295_0s.png)
Java使用DFA算法实现敏感词过滤的示例代码
2022-10-21 00:56:13
![](https://img.aspxhome.com/file/2023/8/77138_0s.png)
SpringCloud hystrix断路器与局部降级全面介绍
2023-10-28 17:29:11
![](https://img.aspxhome.com/file/2023/1/58481_0s.png)
java运行windows的cmd命令简单代码
2021-06-12 11:50:47
![](https://img.aspxhome.com/file/2023/6/85836_0s.png)
Java解决No enclosing instance of type PrintListFromTailToHead is accessible问题的两种方案
2022-10-30 00:31:51
Java遍历Properties所有元素的方法实例
2022-09-08 14:58:24
Android仿XListView支持下拉刷新和上划加载更多的自定义RecyclerView
2023-04-26 12:46:02
![](https://img.aspxhome.com/file/2023/5/139005_0s.gif)
java数据结构与算法之中缀表达式转为后缀表达式的方法
2023-11-22 12:51:35
Android编程开发之在Canvas中利用Path绘制基本图形(圆形,矩形,椭圆,三角形等)
2021-11-16 03:28:09
![](https://img.aspxhome.com/file/2023/5/97875_0s.png)
Java超详细讲解三大特性之一的多态
2022-03-17 02:11:45
![](https://img.aspxhome.com/file/2023/0/119170_0s.png)
Android上传文件到服务器的方法
2021-10-05 21:21:57
![](https://img.aspxhome.com/file/2023/5/101835_0s.jpg)