本文接着《Springboot Actuator之七:actuator 中原生endpoint源码解析1》,前面主要分析了原生endpoint的作用。

现在着重了解actuator的执行原理。

在前面一篇文章中,我们已经了解endpoint的暴露方式有http(spring MVC)协议,jmx协议。

整体实现思路是将端点(Endpoint)适配委托给MVC层策略端点(MvcEndpoint),再通过端点MVC适配器(EndpointMvcAdapter)将端点暴露为HTTP请求方式的MVC端点,最后分别使用端点自动配置(EndpointAutoConfiguration)和MVC方式暴露端点的配置(EndpointWebMvcManagementContextConfiguration)来注入端点组件和端点处理程序映射组件、MVC端点注册表组件、MVC端点组件。

其中,端点处理程序映射(EndpointHandlerMapping)通过Spring MVC方式来暴露MVC端点。最后,本文以“shutdown端点示例”收尾。

现在就按照整体实现思路来剖析HTTP端点的实现原理。

1、端点接口(Endpoint<T>)

其抽象实现基类 AbstractEndpoint<T>

2、MVC层策略端点(MvcEndpoint)

  1. /**
  2. * 实现类允许使用@RequestMapping和完整的Spring MVC机制,
  3. * 但不能在类型级别使用@Controller或@RequestMapping,因为这将导致路径的双重映射,
  4. * 一次通过常规MVC处理程序映射,一次通过{@link EndpointHandlerMapping}。
  5. *
  6. * @author Dave Syer
  7. * @see NamedMvcEndpoint
  8. */
  9. // 核心接口 在端点之上的MVC层策略
  10. public interface MvcEndpoint {
  11.  
  12. /**
  13. * 禁用端点的响应实体
  14. */
  15. ResponseEntity<Map<String, String>> DISABLED_RESPONSE = new ResponseEntity<>(
  16. Collections.singletonMap("message", "This endpoint is disabled"),
  17. HttpStatus.NOT_FOUND);
  18.  
  19. // 核心方法 返回端点的MVC路径
  20. String getPath();
  21.  
  22. /**
  23. * 返回端点是否暴露敏感信息。
  24. */
  25. boolean isSensitive();
  26.  
  27. // 核心方法 返回端点暴露的类型/null
  28. @SuppressWarnings("rawtypes")
  29. Class<? extends Endpoint> getEndpointType();
  30.  
  31. }

2.1、包括逻辑名称的MVC端点(NamedMvcEndpoint)

  1. /**
  2. * 名称提供了引用端点的一致方式。
  3. *
  4. * @author Madhura Bhave
  5. * @since 1.5.0
  6. */
  7. // 包括逻辑名称的MVC端点
  8. public interface NamedMvcEndpoint extends MvcEndpoint {
  9.  
  10. /**
  11. * 返回端点的逻辑名称。
  12. */
  13. String getName();
  14.  
  15. }
  16. }

3、端点MVC适配器(EndpointMvcAdapter)

  1. /**
  2. * 暴露端点({@link Endpoint})为MVC端点({@link MvcEndpoint})的适配器。
  3. */
  4. // 端点MVC适配器
  5. public class EndpointMvcAdapter extends AbstractEndpointMvcAdapter<Endpoint<?>> {
  6.  
  7. /**
  8. * Create a new {@link EndpointMvcAdapter}.
  9. * @param delegate the underlying {@link Endpoint} to adapt. (用于适配的底层端点)
  10. */
  11. public EndpointMvcAdapter(Endpoint<?> delegate) {
  12. super(delegate); // 委托代理
  13. }
  14.  
  15. // 核心实现 以HTTP GET方式调用
  16. @Override
  17. @ActuatorGetMapping
  18. @ResponseBody
  19. public Object invoke() {
  20. return super.invoke(); // 向上调用,链式模式
  21. }
  22. }

@ActuatorGetMapping注解源码:

  1. @Target(ElementType.METHOD)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @RequestMapping(method = RequestMethod.GET, produces = {
  5. ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
  6. MediaType.APPLICATION_JSON_VALUE })
  7. @interface ActuatorGetMapping {
  8.  
  9. /**
  10. * Alias for {@link RequestMapping#value}.
  11. * @return the value
  12. */
  13. @AliasFor(annotation = RequestMapping.class)
  14. String[] value() default {};
  15.  
  16. }

其抽象实现基类 AbstractEndpointMvcAdapter<E extends Endpoint<?>>

  1. /**
  2. * MVC端点({@link MvcEndpoint})实现的抽象基类。
  3. *
  4. * @param <E>
  5. * The delegate endpoint (代理的端点)
  6. * @author Dave Syer
  7. * @since 1.3.0
  8. */
  9. public abstract class AbstractEndpointMvcAdapter<E extends Endpoint<?>> implements NamedMvcEndpoint {
  10.  
  11. /**
  12. * 被代理的底层端点(端点子类)
  13. */
  14. private final E delegate;
  15.  
  16. /**
  17. * 端点URL路径
  18. */
  19. private String path;
  20.  
  21. public AbstractEndpointMvcAdapter(E delegate) {
  22. Assert.notNull(delegate, "Delegate must not be null");
  23. this.delegate = delegate;
  24. }
  25.  
  26. // 核心实现 调用底层端点,并返回调用结果
  27. protected Object invoke() {
  28. if (!this.delegate.isEnabled()) { // 端点被禁用
  29. // Shouldn't happen - shouldn't be registered when delegate's disabled
  30. return getDisabledResponse();
  31. }
  32. return this.delegate.invoke(); // 调用端点
  33. }
  34.  
  35. public E getDelegate() {
  36. return this.delegate;
  37. }
  38.  
  39. @Override
  40. public String getName() {
  41. return this.delegate.getId(); // name = id
  42. }
  43.  
  44. @Override
  45. public String getPath() {
  46. return (this.path != null ? this.path : "/" + this.delegate.getId()); // "/id"
  47. }
  48.  
  49. public void setPath(String path) {
  50. while (path.endsWith("/")) {
  51. path = path.substring(0, path.length() - 1);
  52. }
  53. if (!path.startsWith("/")) {
  54. path = "/" + path;
  55. }
  56. this.path = path;
  57. }
  58.  
  59. @Override
  60. @SuppressWarnings("rawtypes")
  61. public Class<? extends Endpoint> getEndpointType() {
  62. return this.delegate.getClass();
  63. }
  64.  
  65. }

4、端点组件自动配置

基于Spring Boot的自动配置机制(Auto-configuration),其自动配置文件位于spring-boot-actuator资源目录下的META-INF/spring.factories文件:

  1. # 启用自动配置
  2. org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  3. ...
  4. org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration,\
  5. ...
  6.  
  7. # 管理上下文配置
  8. org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=\
  9. org.springframework.boot.actuate.autoconfigure.EndpointWebMvcManagementContextConfiguration,\
  10. ...

4.1、公共管理的端点自动配置(EndpointAutoConfiguration)

4.2、全局的端点属性(EndpointProperties)

4.3、外部化配置的注解(ConfigurationProperties)

  1. /**
  2. * 如果要绑定和验证一些外部属性(例如来自.properties文件),请将其添加到@Configuration类中的类定义或@Bean方法。
  3. */
  4. // 外部化配置的注解
  5. @Target({ ElementType.TYPE, ElementType.METHOD })
  6. @Retention(RetentionPolicy.RUNTIME)
  7. @Documented
  8. public @interface ConfigurationProperties {
  9.  
  10. // 属性的名称前缀
  11. @AliasFor("value")
  12. String prefix() default "";
  13.  
  14. }

5、MVC方式暴露端点的配置(EndpointWebMvcManagementContextConfiguration)

  1. // 核心类 通过MVC方式来暴露端点的配置
  2. @ManagementContextConfiguration
  3. @EnableConfigurationProperties({ HealthMvcEndpointProperties.class, EndpointCorsProperties.class })
  4. public class EndpointWebMvcManagementContextConfiguration {
  5.  
  6. private final HealthMvcEndpointProperties healthMvcEndpointProperties;
  7.  
  8. /**
  9. * 管理服务器的属性
  10. */
  11. private final ManagementServerProperties managementServerProperties;
  12.  
  13. private final EndpointCorsProperties corsProperties;
  14.  
  15. /**
  16. * 端点处理程序的映射定制程序
  17. */
  18. private final List<EndpointHandlerMappingCustomizer> mappingCustomizers;
  19.  
  20. // 核心方法 注入端点处理程序映射组件
  21. @Bean
  22. @ConditionalOnMissingBean // 组件未注入
  23. public EndpointHandlerMapping endpointHandlerMapping() {
  24. // 注册的MVC端点集合
  25. Set<MvcEndpoint> endpoints = mvcEndpoints().getEndpoints();
  26. CorsConfiguration corsConfiguration = getCorsConfiguration(this.corsProperties);
  27. // 端点处理程序映射
  28. EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints, corsConfiguration);
  29. // 管理端点的上下文路径前缀
  30. mapping.setPrefix(this.managementServerProperties.getContextPath());
  31. // MVC端点安全处理程序拦截器
  32. MvcEndpointSecurityInterceptor securityInterceptor = new MvcEndpointSecurityInterceptor(
  33. this.managementServerProperties.getSecurity().isEnabled(),
  34. this.managementServerProperties.getSecurity().getRoles());
  35. mapping.setSecurityInterceptor(securityInterceptor);
  36. for (EndpointHandlerMappingCustomizer customizer : this.mappingCustomizers) {
  37. customizer.customize(mapping);
  38. }
  39. return mapping;
  40. }
  41.  
  42. // 核心方法 注入MVC端点注册表组件
  43. @Bean
  44. @ConditionalOnMissingBean // 组件未注入
  45. public MvcEndpoints mvcEndpoints() {
  46. return new MvcEndpoints();
  47. }
  48.  
  49. @Bean
  50. @ConditionalOnBean(EnvironmentEndpoint.class)
  51. @ConditionalOnEnabledEndpoint("env")
  52. public EnvironmentMvcEndpoint environmentMvcEndpoint(EnvironmentEndpoint delegate) {
  53. return new EnvironmentMvcEndpoint(delegate);
  54. }
  55.  
  56. @Bean
  57. @ConditionalOnBean(HealthEndpoint.class)
  58. @ConditionalOnEnabledEndpoint("health")
  59. public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) {
  60. HealthMvcEndpoint healthMvcEndpoint = new HealthMvcEndpoint(delegate,
  61. this.managementServerProperties.getSecurity().isEnabled());
  62. if (this.healthMvcEndpointProperties.getMapping() != null) {
  63. healthMvcEndpoint.addStatusMapping(this.healthMvcEndpointProperties.getMapping());
  64. }
  65. return healthMvcEndpoint;
  66. }
  67.  
  68. // 注入关闭应用程序的MVC端点组件
  69. @Bean
  70. @ConditionalOnBean(ShutdownEndpoint.class) // 组件已实例化
  71. @ConditionalOnEnabledEndpoint(value = "shutdown", enabledByDefault = false) // 端点已启用
  72. public ShutdownMvcEndpoint shutdownMvcEndpoint(ShutdownEndpoint delegate) {
  73. return new ShutdownMvcEndpoint(delegate);
  74. }
  75.  
  76. }

5.1、MVC端点注册表(MvcEndpoints)

1、MvcEndpoints实现了ApplicationContextAware,取ApplicationContext;

2、MvcEndpoints实现了InitializingBean ,在容器启动后调用afterPropertiesSet()方法适配那些通用的endpoint;

  1.  
  1. * 所有MVC端点组件的注册表,以及一组用于包装尚未公开的MVC端点的现有端点实例的通用工厂。
  2. */
  3. // 核心类 MVC端点注册表
  4. public class MvcEndpoints implements ApplicationContextAware, InitializingBean {
  5.  
  6. /**
  7. * 应用上下文
  8. */
  9. private ApplicationContext applicationContext;
  10.  
  11. /**
  12. * MVC端点集合
  13. */
  14. private final Set<MvcEndpoint> endpoints = new HashSet<>();
  15.  
  16. /**
  17. * MVC端点类型集合
  18. */
  19. private Set<Class<?>> customTypes;
  20.  
  21. @Override
  22. public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  23. this.applicationContext = applicationContext;
  24. }
  25.  
  26. @Override
  27. public void afterPropertiesSet() throws Exception {
  28. //1、从applicationContext中检索出来已经实例化的MVC端点列表
  29. Collection<MvcEndpoint> existing = BeanFactoryUtils
  30. .beansOfTypeIncludingAncestors(this.applicationContext, MvcEndpoint.class) // MVC端点
  31. .values();
  32. this.endpoints.addAll(existing);
  33. this.customTypes = findEndpointClasses(existing);
  34. //2、从applicationContext中检索出来已经实例化的代理端点列表
  35. @SuppressWarnings("rawtypes")
  36. Collection<Endpoint> delegates = BeanFactoryUtils
  37. .beansOfTypeIncludingAncestors(this.applicationContext, Endpoint.class) // 端点
  38. .values();
  39. for (Endpoint<?> endpoint : delegates) {
  40. //3、判断是否是通用的endpoint
  41. if (isGenericEndpoint(endpoint.getClass()) && endpoint.isEnabled()) {
  42. EndpointMvcAdapter adapter = new EndpointMvcAdapter(endpoint); // 端点MVC适配器
  43. // 端点路径
  44. String path = determinePath(endpoint, this.applicationContext.getEnvironment());
  45. if (path != null) {
  46. adapter.setPath(path);
  47. }
  48. this.endpoints.add(adapter);
  49. }
  50. }
  51. }
  52.  
  53. private Set<Class<?>> findEndpointClasses(Collection<MvcEndpoint> existing) {
  54. Set<Class<?>> types = new HashSet<>();
  55. for (MvcEndpoint endpoint : existing) {
  56. Class<?> type = endpoint.getEndpointType(); // 端点类型
  57. if (type != null) {
  58. types.add(type);
  59. }
  60. }
  61. return types;
  62. }
  63.  
  64. // 核心方法 返回注册的MVC端点集合
  65. public Set<MvcEndpoint> getEndpoints() {
  66. return this.endpoints;
  67. }
  68.  
  69. /**
  70. * 返回指定类型的MVC端点集合。
  71. */
  72. @SuppressWarnings("unchecked")
  73. public <E extends MvcEndpoint> Set<E> getEndpoints(Class<E> type) {
  74. Set<E> result = new HashSet<>(this.endpoints.size());
  75. for (MvcEndpoint candidate : this.endpoints) {
  76. if (type.isInstance(candidate)) {
  77. result.add((E) candidate);
  78. }
  79. }
  80. return Collections.unmodifiableSet(result); // 不可修改的集合
  81. }
  82.  
  83. // 判断是否是通用的端点
  84. private boolean isGenericEndpoint(Class<?> type) {
  85. return
  86. //第一步中扫描的已经实例化的MVC端点中不存在
  87. !this.customTypes.contains(type)
  88. //确定此类对象表示的类或接口是否与由指定的类参数表示的类或接口相同,或者是该类或接口的超类或超接口。
  89. && !MvcEndpoint.class.isAssignableFrom(type);
  90. }
  91.  
  92. private String determinePath(Endpoint<?> endpoint, Environment environment) {
  93. // 配置属性
  94. ConfigurationProperties configurationProperties = AnnotationUtils.findAnnotation(endpoint.getClass(),
  95. ConfigurationProperties.class);
  96. if (configurationProperties != null) {
  97. return environment.getProperty(configurationProperties.prefix() + ".path");
  98. }
  99. return null;
  100. }
  101.  
  102. }

5.2、端点处理程序映射(EndpointHandlerMapping)

  1. /**
  2. * handlerMapping通过endpoint.getid()将端点映射到URL。@RequestMapping的语义应该与普通的@Controller相同,
  3. * 但是端点不应该被注释为@Controller,否则它们将被正常的MVC机制映射。 <p>
  4. * <p>
  5. * 映射的目标之一是支持作为HTTP端点工作的端点, 但是当没有HTTP服务器(类路径上没有Spring MVC)时,仍然可以提供有用的服务接口。
  6. * 注意:具有方法签名的任何端点将在非Servlet环境下中断。
  7. */
  8. // 核心类 通过端点的逻辑标识将端点映射到URL的处理程序映射
  9. public class EndpointHandlerMapping extends AbstractEndpointHandlerMapping<MvcEndpoint> {
  10.  
  11. /**
  12. * Create a new {@link EndpointHandlerMapping} instance. All {@link Endpoint}s
  13. * will be detected from the {@link ApplicationContext}. The endpoints will
  14. * accepts CORS requests based on the given {@code corsConfiguration}.
  15. *
  16. * @param endpoints
  17. * the endpoints (MVC端点列表)
  18. * @param corsConfiguration
  19. * the CORS configuration for the endpoints
  20. * @since 1.3.0
  21. */
  22. public EndpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints, CorsConfiguration corsConfiguration) {
  23. super(endpoints, corsConfiguration);
  24. }
  25.  
  26. }

其抽象实现基类 AbstractEndpointHandlerMapping<E extends MvcEndpoint>

  1. package com.dxz.inject;
  2.  
  3. /**
  4. * @RequestMapping的语义应该与普通的@Controller相同, 但是端点不应该被注释为@Controller,否则它们将被正常的MVC机制映射。
  5. * 映射的目标之一是支持作为HTTP端点工作的端点,但是当没有HTTP服务器(类路径上没有Spring MVC)时,仍然可以提供有用的服务接口。
  6. * 注意:具有方法签名的任何端点将在非Servlet环境下中断。
  7. *
  8. * @param <E>
  9. * The endpoint type (端点类型)
  10. */
  11. // 核心类 通过端点的逻辑标识将端点映射到URL的处理程序映射的抽象基类
  12. public abstract class AbstractEndpointHandlerMapping<E extends MvcEndpoint> extends RequestMappingHandlerMapping {
  13.  
  14. /**
  15. * MVC端点集合
  16. */
  17. private final Set<E> endpoints;
  18.  
  19. /**
  20. * 安全处理程序拦截器
  21. */
  22. private HandlerInterceptor securityInterceptor;
  23.  
  24. /**
  25. * CORS配置
  26. */
  27. private final CorsConfiguration corsConfiguration;
  28.  
  29. /**
  30. * 端点的映射路径前缀
  31. */
  32. private String prefix = "";
  33.  
  34. private boolean disabled = false;
  35.  
  36. /**
  37. * <p>
  38. * 将从应用上下文检测到所有端点。
  39. */
  40. public AbstractEndpointHandlerMapping(Collection<? extends E> endpoints, CorsConfiguration corsConfiguration) {
  41. this.endpoints = new HashSet<>(endpoints);
  42. postProcessEndpoints(this.endpoints);
  43. this.corsConfiguration = corsConfiguration;
  44. // By default the static resource handler mapping is LOWEST_PRECEDENCE - 1
  45. // and the RequestMappingHandlerMapping is 0 (we ideally want to be before both)
  46. // 默认情况下,静态资源处理程序映射的顺序是 LOWEST_PRECEDENCE - 1
  47. setOrder(-100);
  48. setUseSuffixPatternMatch(false);
  49. }
  50.  
  51. /**
  52. * Post process the endpoint setting before they are used. Subclasses can add or
  53. * modify the endpoints as necessary.
  54. * <p>
  55. * 在使用之前,后处理端点设置。
  56. *
  57. * @param endpoints
  58. * the endpoints to post process
  59. */
  60. protected void postProcessEndpoints(Set<E> endpoints) {
  61. }
  62.  
  63. @Override
  64. public void afterPropertiesSet() {
  65. super.afterPropertiesSet();
  66. if (!this.disabled) { // 端点处理程序被禁用
  67. for (MvcEndpoint endpoint : this.endpoints) {
  68. detectHandlerMethods(endpoint);
  69. }
  70. }
  71. }
  72.  
  73. // 核心实现 注册端点处理程序方法及其唯一映射
  74. @Override
  75. @Deprecated
  76. protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) {
  77. if (mapping == null) {
  78. return;
  79. }
  80. String[] patterns = getPatterns(handler, mapping);
  81. if (!ObjectUtils.isEmpty(patterns)) {
  82. super.registerHandlerMethod(handler, method, withNewPatterns(mapping, patterns));
  83. }
  84. }
  85.  
  86. private String[] getPatterns(Object handler, RequestMappingInfo mapping) {
  87. if (handler instanceof String) { // 组件名称
  88. handler = getApplicationContext().getBean((String) handler);
  89. }
  90. Assert.state(handler instanceof MvcEndpoint, "Only MvcEndpoints are supported");
  91. String path = getPath((MvcEndpoint) handler); // MVC端点路径
  92. return (path == null ? null : getEndpointPatterns(path, mapping));
  93. }
  94.  
  95. protected String getPath(MvcEndpoint endpoint) {
  96. return endpoint.getPath();
  97. }
  98.  
  99. // 核心实现 返回端点的路径列表
  100. private String[] getEndpointPatterns(String path, RequestMappingInfo mapping) {
  101. // 路径模式前缀
  102. String patternPrefix = StringUtils.hasText(this.prefix) ? this.prefix + path : path;
  103. // 默认的路径集合
  104. Set<String> defaultPatterns = mapping.getPatternsCondition().getPatterns();
  105. if (defaultPatterns.isEmpty()) {
  106. // 端点路径
  107. return new String[] { patternPrefix, patternPrefix + ".json" };
  108. }
  109. List<String> patterns = new ArrayList<>(defaultPatterns);
  110. for (int i = 0; i < patterns.size(); i++) {
  111. patterns.set(i, patternPrefix + patterns.get(i)); // 端点请求路径
  112. }
  113. return patterns.toArray(new String[patterns.size()]);
  114. }
  115.  
  116. // 新的端点路径
  117. private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping, String[] patternStrings) {
  118. // 模式请求条件
  119. PatternsRequestCondition patterns = new PatternsRequestCondition(patternStrings, null, null,
  120. useSuffixPatternMatch(), useTrailingSlashMatch(), null);
  121. return new RequestMappingInfo(patterns, mapping.getMethodsCondition(), mapping.getParamsCondition(),
  122. mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(),
  123. mapping.getCustomCondition());
  124. }
  125.  
  126. // 核心实现 获取处理程序执行链
  127. @Override
  128. protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
  129. HandlerExecutionChain chain = super.getHandlerExecutionChain(handler, request);
  130. if (this.securityInterceptor == null || CorsUtils.isCorsRequest(request)) {
  131. return chain;
  132. }
  133. return addSecurityInterceptor(chain);
  134. }
  135.  
  136. private HandlerExecutionChain addSecurityInterceptor(HandlerExecutionChain chain) {
  137. // 处理程序拦截器
  138. List<HandlerInterceptor> interceptors = new ArrayList<>();
  139. if (chain.getInterceptors() != null) {
  140. interceptors.addAll(Arrays.asList(chain.getInterceptors()));
  141. }
  142. // 添加安全处理程序拦截器
  143. interceptors.add(this.securityInterceptor);
  144. return new HandlerExecutionChain(chain.getHandler(),
  145. interceptors.toArray(new HandlerInterceptor[interceptors.size()]));
  146. }
  147.  
  148. // 获取端点的路径
  149. public String getPath(String endpoint) {
  150. return this.prefix + endpoint;
  151. }
  152.  
  153. // 返回MVC端点集合
  154. public Set<E> getEndpoints() {
  155. return Collections.unmodifiableSet(this.endpoints); // 不可修改的集合
  156. }
  157.  
  158. }

5.3、组件存在条件(OnBeanCondition)
5.3.1、未注入组件条件(ConditionalOnMissingBean)

5.3.2、组件条件(ConditionalOnBean)

6、shutdown端点示例

6.1、关闭应用程序的端点(ShutdownEndpoint)

6.2、关闭应用程序的MVC端点(ShutdownMvcEndpoint)

  1. /**
  2. * 暴露关闭应用上下文端点({@link ShutdownEndpoint})为MVC端点({@link MvcEndpoint})的适配器。
  3. */
  4. // 关闭应用程序的MVC端点
  5. @ConfigurationProperties(prefix = "endpoints.shutdown") // 属性前缀配置
  6. public class ShutdownMvcEndpoint extends EndpointMvcAdapter {
  7.  
  8. public ShutdownMvcEndpoint(ShutdownEndpoint delegate) {
  9. super(delegate); // 委托代理
  10. }
  11.  
  12. // 核心实现 以HTTP POST方式调用
  13. @PostMapping(produces = { ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
  14. @ResponseBody
  15. @Override
  16. public Object invoke() {
  17. if (!getDelegate().isEnabled()) { // 端点被禁用
  18. return getDisabledResponse();
  19. }
  20. return super.invoke(); // 向上调用,链式模式
  21. }
  22.  
  23. }

原文:https://blog.csdn.net/shupili141005/article/details/61476546

Springboot Actuator之八:actuator的执行原理的更多相关文章

  1. 【spring cloud】【spring boot】网管服务-->配置文件添加endpoints.enabled = false,SpringBoot应用监控Actuator使用的安全隐患

    转载:https://xz.aliyun.com/t/2233 ==================================================================== ...

  2. SpringBoot执行原理

    目录 [Toc] 一.执行原理: 每个Spring Boot项目都有一个主程序启动类,在主程序启动类中有一个启动项目的main()方法, 在该方法中通过执行SpringApplication.run( ...

  3. springboot项目启动成功后执行一段代码的两种方式

    springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springf ...

  4. Javascript之数据执行原理探究

    Javascript在Web服务器端执行原理: 1.客户端请求数据,即我们在上网时在地址栏中输入某个网址,浏览器接收到数据之后,向远程web服务器发送请求报文. 2.web服务器响应请求,web服务器 ...

  5. Python程序的执行原理(转载)

    Python程序的执行原理 2013-09-17 10:35 佚名 tech.uc  1. 过程概述 Python先把代码(.py文件)编译成字节码,交给字节码虚拟机,然后虚拟机一条一条执行字节码指令 ...

  6. smarty模板执行原理

    为了实现程序的业务逻辑和内容表现页面的分离从而提高开发速度,php 引入了模板引擎的概念,php 模板引擎里面最流行的可以说是smarty了,smarty因其功能强大而且速度快而被广大php web开 ...

  7. MapReduce调度与执行原理之任务调度

    前言 :本文旨在理清在Hadoop中一个MapReduce作业(Job)在提交到框架后的整个生命周期过程,权作总结和日后参考,如有问题,请不吝赐教.本文不涉及Hadoop的架构设计,如有兴趣请参考相关 ...

  8. MapReduce调度与执行原理之作业提交

    前言 :本文旨在理清在Hadoop中一个MapReduce作业(Job)在提交到框架后的整个生命周期过程,权作总结和日后参考,如有问题,请不吝赐教.本文不涉及Hadoop的架构设计,如有兴趣请参考相关 ...

  9. MapReduce调度与执行原理之作业初始化

    前言 :本文旨在理清在Hadoop中一个MapReduce作业(Job)在提交到框架后的整个生命周期过程,权作总结和日后参考,如有问题,请不吝赐教.本文不涉及Hadoop的架构设计,如有兴趣请参考相关 ...

随机推荐

  1. es6的let与const

    es6新增命令let,用于声明变量,他与var的不同主要有三点: let有块级作用域 let没有变量提升 同级作用域内,let不可以重复定义 let有块级作用域: es5 for(var i=0;i& ...

  2. 使用Fiddler监听java HttpURLConnection请求

    使用Fiddler监听java HttpURLConnection请求

  3. 搜索引擎框架之ElasticSearch基础详解(非原创)

    文章大纲 一.搜索引擎框架基础介绍二.ElasticSearch的简介三.ElasticSearch安装(Windows版本)四.ElasticSearch操作客户端工具--Kibana五.ES的常用 ...

  4. 微信小程序+php 授权登陆,完整代码

    先上图        实现流程: 1.授权登陆按钮和正文信息放到了同一个页面,未授权的时候显示登陆按钮,已授权的时候隐藏登陆按钮,显示正文信息,当然也可以授权和正文分开成两个页面,在授权页面的onlo ...

  5. ThinkPHP3.2.3:使用模块映射隐藏后台真实访问地址(如:替换url里的admin字眼)

    例如:项目应用目录/Application下模块如下,默认后台模块为Admin 现在需要修改后台模块的访问地址,以防被别有用心的人很容易就猜到,然后各种乱搞... (在公共配置文件/Applicati ...

  6. 阿里云查看本服务器 公网ip地址 命令

    阿里云的服务器用命令ifconfig查看的是本机内网地址 那如何访问公网地址呢? curl httpbin.org/ip

  7. Linux shell sed命令使用

    Linux处理文本文件的工具:     grep        过滤文件内容     sed            编辑文件内容     awk             正则表达式Regex      ...

  8. Kubernetes基础服务架构图

    最近看了一些kubernetes的相关资料, 简单的画了一个原理图 欢迎大家批阅

  9. Linux操作系统的打包/归档工具介绍

    Linux操作系统的打包/归档工具介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.

  10. js冒泡排序,快速排序,插入排序

     //冒泡排序 function sortBubble(array){   var len=array.length,i,j,tmp;   for(i=len-1;i>=1;i--){     ...