特斯拉高管:特斯拉公司在湖北武汉重开展厅
下一篇
英文原文:https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/ht% R ^ K 5 y * f -ml/production-ready-endpoints.htmlGitHub:https://github.com/jijicai/Spring/tree/master/spring-bo= Y c pth 显示应用程序运行状况信息。 Yes
httptrace 显示 HTTP 跟踪信息(默认情况下,最后 100 个 HTTP 请求u L P n 8 K 3 X-响应交换)。 Yes
info 显示任意应用程序信息。 Yes
integrationgraph 显示 Spring 集成图。 Yes
loggers 显示和修改应用程序中记录器的配置。 Yes
liqI 2 _uibase 显示已应用的任何 Liquibase 数据库迁移。 Yes
metrics 显示当前应用程序的“度量”信息。 Yes
mappings 显示所k V @ 8 y ` 1 r有 @RequestMapping 路径的U V % !整理列表。 Yes
sA ( k b * _ h %cheduledtasks 显示应用程序中的计划任务。 Yes
sessions 允许从支l | + =持 Spring Session 的会话存储中检( + [索和删除用户会话。在使用 Spring Session 对反应式 web 应用o 3 G p程序的支持时不可用。 Yes
shutdown 允许优雅地关闭应用程序。 No
threaddump 执行线程转储。 Yes如果你的应用程序是 web 应用程序(Spring MVC 、 Spring WebFlux 或 Jersey),则可以使d - f 1 ! b Q用以下附加端点:
ID 描述 默认启用
heapdump 返回 hprof 堆转储文件。M q k & l z F Yes
jolokia 通过 HTTP 公开 JMm ` 0 A r a + EX bean(当 Jolokia 在类路径上时,WebFlux 不可用)h ; _ W。 Yr p p L + 7es
logfile 返回日志文件的内容(如果已设置 logg+ l G I T ^ U K Ping.file 或 logging.path 属性)。支持使用 HTTP Range 头来检索日志文件的部分内容。 Yes
prometheus 以 Prometheus 服务器可以抓取的格式公开度量& e [ O 2 E。 Yes要了解有关 Actuator 端点及其请& g . )求和响应格式的更多信息,请参阅单独的 API 文档(HTML 或 PDFz p % ?)。
53.1、启用端点
默认情况下,启用除 shutdoD @ t U d 6wn 以外的所有端点。要配置端点的启用,请使用其 manaF = d g g e *gemen; e [ ; C r m Dt.endpoint.<id>.enabled 属性。以下示例启用 shutdown 端点:
management.endpoint.shutd_ P z f Kown.enabled=true如果你希望端点启用是 opt-in(选入k C } e [ , d 5 g) 而不是 opt-out(退出,不参与),请将 management.` N x 6 K % {endpoints.enabled-by-default 属性设置为 false,并使用各个端点的 enabled 属性选择重新启用。以下示例启用 info 端点并禁用所有其他端点:
manN v t B h o G aagement.endpoints.enabled-by-default=false
manageme8 i a x o w H |nt.endpoint.info.enabled=trueM r I } ) l L注释:禁用的端点Z j N C B C c . @ ) )所有端点,而只公开 health 和 info 端点,请使用以下属性:
management.endpoints.jmx.exposure.includ_ [ 5 + ce=health,info*b i d R 可用于选择所有端点。例如,要通过 HTTP 公开除a 0 W F H N S Q env 和 beans 之外的所有端点,请使用J V v c以下属性:
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans注释:
* 在 YAML 中具有特殊含义,因此,如果要包括(或排除)所有端点4 a L 5 z S r 2 },请务必添加引号,如下例所示:
management:
endpoints:
web:
exposure:
include: \"*\"注释:如果你的应用程序公开,我们强烈建议你也保护你的端点。(ht? x N U ftps://docs.c d G 2 ~ r 2 %spring.io/spring-boot/docs/2.1.6.RELEASE/referenI L w H C 5ce/html/production-ready-endpoints.html#production-ready-endpoints-s[ ~ f ? v ~ j D #ecurity )
提示:如果你想在公开端点时实现自己的策略,可以注册 EndpointFilter bean。
53.3、保护 HTTP 端点
你应该像保护任何其他敏感 URL 一样小心保护 HTTP 端点。如果存在 Spring Security,则默9 & l t q认情况下使用 Spring Sen ) L U Z d @curity 的内容协商策略来保护端点。如果你希望为 HTTP 端点配置自定义安全8 e ~ } 8 W %性,例如,仅允许具有特定角色的用户访问它们, Spring Boot 提供了一些方便的 RequestMatcher 对象,这些对象可以与 Spring Security 结合使用。
典型的 Spring Security 配置可能类C H } l ( b j ?似于以下示例:
@Configuration
pa 1 s T V hubli7 : b # m & d -c class ActuatorSecurity exB 6 stends WebS~ [ 5 F # LecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRp ) X equests()
.anyRequest().hasRole(\"ENDPOINT_ADMIN\")
.and()
.httpBasic();
}
}上述示例使用 EndpointRequest.toAnyEndpoint() 将Q C A g l h t w请求# F U与任何` ) G 4 s + C = Z端点匹配,T b A B } l Z然后确保所有端点都具有 ENDPOINw e YT_ADMIN 角色。EndpointRequest 上还提供了其他几种匹配器方法。有关详细信息,% i 2 @ * % / 请参阅 API 文档(HTML 或 PDF)。
如果你在防火墙后部署应用程序,你可能希望可以访问所有 actuator 端点,而不需要身份验证。可以通过更改 management.endpoints.web.exposure.include 属性来执行此操作,如下所示:
application.properties
management.endpoints.web.expos- E & F H &ure.includex n } % / Z S=*此外,如果存在 Spring Security,则需要添加自定义安全L ` 9 H配置,以允许未经身份验证的对端点的访问,如下面示例所示:
@CK r ~ e E % | S Sonfiguration
public class ActuatorSecurity exR B G * 3 . O jtends Webh F c [ t D $ { OSecurityConfiguz Y hrerAdapter {
@Override
pro4 @ Ptected void configure(HttpSecu, 8 p e i 5rity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint(_ i * X 4 B j T *)).authoriu { B ) z G S +zeRequests()
.anyRequest().permitAll();
}
}下一篇