程序監控

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.