springboot actuator shutdown正确的关闭操作

今天整合ehcache时发现一个很重要的问题,就是程序关闭(硬关闭)之后,持久化到磁盘的缓存数据没能正确写入加载,问题还是硬关闭的问题,所以就使用actuator 进行监听

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

application.properties中添加(这里使用的是springboot2.x,所以management.endpoint替换了1.x的endpoints)

#启用shutdown

management.endpoint.shutdown.enabled=true

重启之后(/actuator 查看添加的监听接口)发现是没有需要的(/shutdown)

{
    "_links": {
        "self": {
            "href": "http://localhost:8082/actuator",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8082/actuator/health",
            "templated": false
        },
        "info": {
            "href": "http://localhost:8082/actuator/info",
            "templated": false
        }
    }
}

application.properties中添加

management.endpoints.web.exposure.include=*

(/actuator/shutdown)正常返回

{
    "message": "Shutting down, bye..."
}

 修改默认(/actuator)前缀路径)application.properties中添加

management.endpoints.web.base-path=/system/actuator

 

转载于:https://www.cnblogs.com/skyLogin/p/9214575.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot Actuator是Spring Boot提供的一个管理和监控应用程序的工具集。它提供了一些有用的端点(Endpoints),可以让你查看和管理Spring Boot应用程序的运行状态,如健康状态、内存使用情况、线程信息等等。 下面是Spring Boot Actuator正确使用方法: 1. 引入依赖 在pom.xml中添加以下依赖: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ``` 2. 配置端点 在application.properties中配置端点: ``` management.endpoints.web.exposure.include=* ``` 上述配置将所有的端点都暴露出来,如果你只想暴露特定端点,可以使用以下配置: ``` management.endpoints.web.exposure.include=health,info ``` 3. 查看端点 启动应用程序后,可以通过以下URL查看端点: ``` http://localhost:8080/actuator ``` 这将显示所有可用的端点。例如,要查看健康状态,可以使用以下URL: ``` http://localhost:8080/actuator/health ``` 4. 自定义端点 可以通过实现Endpoint接口来自定义端点,例如: ``` @Component public class CustomEndpoint implements Endpoint<Map<String, Object>> { @Override public String getId() { return "custom"; } @Override public boolean isEnabled() { return true; } @Override public boolean isSensitive() { return true; } @Override public Map<String, Object> invoke() { Map<String, Object> result = new HashMap<>(); result.put("message", "Hello, world!"); return result; } } ``` 在应用程序中注入该组件,然后可以通过以下URL访问自定义端点: ``` http://localhost:8080/actuator/custom ``` 以上就是Spring Boot Actuator正确使用方法,它可以帮助你更好地管理和监控Spring Boot应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值