进程监控

spring-boot 模块中,你可以找到两个类来创建对进程监控通常有用的文件。

  • ApplicationPidFileWriter 创建一个包含应用程序 PID 的文件(默认情况下,在应用程序目录中,文件名为 application.pid)。

  • WebServerPortFileWriter 创建一个或多个文件,其中包含正在运行的 Web 服务器的端口(默认情况下,在应用程序目录中,文件名为 application.port)。

默认情况下,这些写入器未激活,但你可以启用它们。

扩展配置

META-INF/spring.factories 文件中,你可以激活写入 PID 文件的监听器。

org.springframework.context.ApplicationListener=\
org.springframework.boot.context.ApplicationPidFileWriter,\
org.springframework.boot.web.context.WebServerPortFileWriter

以编程方式启用进程监控

你还可以通过调用 SpringApplication.addListeners(…​) 方法并传递适当的 Writer 对象来激活监听器。此方法还允许你在 Writer 构造函数中自定义文件名称和路径。

© . This site is unofficial and not affiliated with VMware.