spring-boot-starter-actuator 2.0.3.RELEASE 使用-配置文件生效

写在前面的话

spring-boot 组件更新比较频繁,一般的项目组很少会同步更新版本,往往遇到问题解决问题,这样固然降低人员成本,但同时增加的长期的项目风险,加上不尽人意的搜索结果,往往是大半天时间在解决一个小问题,最后不得不冒着兼容风险通过修改版本来实现。

spring-boot-starter-actuator 配置问题

启动日志显示 Actuator只暴露health和info

o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path ‘/actuator’
s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped “{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}” onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping O p e r a t i o n H a n d l e r . h a n d l e ( j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t R e q u e s t , j a v a . u t i l . M a p &lt; j a v a . l a n g . S t r i n g , j a v a . l a n g . S t r i n g &gt; ) s . b . a . e . w . s . W e b M v c E n d p o i n t H a n d l e r M a p p i n g : M a p p e d &quot; [ / a c t u a t o r / i n f o ] , m e t h o d s = [ G E T ] , p r o d u c e s = [ a p p l i c a t i o n / v n d . s p r i n g b o o t . a c t u a t o r . v 2 + j s o n a p p l i c a t i o n / j s o n ] &quot; o n t o p u b l i c j a v a . l a n g . O b j e c t o r g . s p r i n g f r a m e w o r k . b o o t . a c t u a t e . e n d p o i n t . w e b . s e r v l e t . A b s t r a c t W e b M v c E n d p o i n t H a n d l e r M a p p i n g OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map&lt;java.lang.String, java.lang.String&gt;) s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped &quot;{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}&quot; onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped “{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}” onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

没有文档上介绍的beans …

直觉应该是配置文件问题,网上资料一大堆
梳理下三种解决思路:

1.没有spring-boot-starter-security

按道理两个组件各司其职没有关系,保险起见我还是实践了一下,确实没有关系,后期也需要控制暴露的地址权限

2.配置文件错误

网上资料大部分明确了配置原因,但没有给我正确的配置,或许是版本更新问题
试过;
此配置不生效

management:
  health:
    mail:
      enabled: false
  endpoints:
    web:
      base-path: /manage
      exposure:
        include: *

或者
此配置不生效

management:
  health:
    mail:
      enabled: false
  endpoints:
    web:
      base-path: /manage
      exposure:
        include: "*"

常见的解决配置,有些properties形式
现在怎么办,找正确的配置,官方文档里搜一波,无果
继续看配置文件:
idea 在你写配置文件的时候有提示,包含参数,

在这里插入图片描述

看到了[“health’] 试了一下成功
那么推测 [”*"] 会显示所有连接
在这里插入图片描述

效果如下:

在这里插入图片描述

生效的配置:

management:
  health:
    mail:
      enabled: false
  endpoints:
    web:
      base-path: /manage
      exposure:
        include: ["*"]

总结:
随着web技术栈的发展,以前servlet +html+mysql的架构逐步复杂到了
springcloud+mybaties+连接池+nosql
+前端框架+Redis 尽管每个组件都经过了充分实践,但仍然有很多细节不为人知,
在技术选型的时候,要控制技术栈的广度和深度,不是所有公司的项目组都能聚集一批高手,人员流动的风险往往忽视,相对于付费组件,这些技术的成本看似为0 但仍需要通过人员的投入去把控开源组件的风险,否则项目越大,遇到的问题越多。

参考[link]:https://blog.csdn.net/love3765/article/details/79291584
参考[link]:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/#beans-retrieving-response-structure
参考[link]https://blog.csdn.net/qq_20367813/article/details/79154981

猜你喜欢

转载自blog.csdn.net/keep_learn/article/details/86167117