130.【Spring注解_AOP】(一)

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 130.【Spring注解_AOP】

130.【Spring注解_AOP】

Spring 注解


(一)、AOP功能测试

AOP是指在程序的运行期间动态地将某段代码切入到指定方法、指定位置进行运行的编程方式。AOP的底层是使用动态代理实现的。

1.AOP 使用步骤

* AOP【动态代理】 : 指在程序运行期间动态的将某段代码切入到指定方法指定位置进行运行的编程方式;
 *                  1.如何使用?
 *                      (1).导入AOP的依赖。
 *                      (2).定义一个业务逻辑类(MathCalculator)。在业务逻辑运行的时候将日志进行打印(方法之前,方法结束,方法异常)
 *                      (3).定义一个日志切面类(LogAspect)。切面类里面的方法需要动态的感知 业务逻辑类(MathCalculator)的运行情况
 *                              (3.1).通知方法: 前置通知@Before(在目标方法运行之前运行),
 *                                              后置通知@After(在目标方法运行之后运行,不在意正常结束还是异常结束),
 *                                              返回通知@AfterReturning(在目标方法正常返回之后运行),
 *                                              异常通知@AfterThrowing(在目标方法发生异常之后运行),
 *                                              环绕通知@Round(动态代理,手动推进目标方法运行 joinPoint.)
 *                      (4).给切面类(LogAspect)的目标方法标注何时何处地运行 (通知注解)
 *                      (5).将切面类和业务逻辑类(目标方法所在类) 都加入到容器中
 *                      (6).必须告诉Spring的IOC容器哪个类是切面类(我们需要给切面类添加一个注解 @Aspect)
 *                      (7).在配置类上开启 注解版的切面功能 ( <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  @EnableAspectJAutoProxy)
 *                      (8).测试,这个逻辑类一定要使用IOC容器的类,不能使用new
(1).导入AOP对应的依赖
<!--    Spring切面的包    -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>4.3.12.RELEASE</version>
        </dependency>
(2).编写业务逻辑类
package com.jsxs.aop;
/**
 * @Author Jsxs
 * @Date 2023/8/19 11:49
 * @PackageName:com.jsxs.aop
 * @ClassName: MathCalculator
 * @Description: TODO
 * @Version 1.0
 */
public class MathCalculator {
    public int div(int x,int y){
        return x/y;
    }
}
(3).编写切面
  1. 使用非公共切入点 @Pointcut

标注是切面的注解,且使用四个通知方法和公共切点注解

package com.jsxs.aop;
import org.aspectj.lang.annotation.*;
/**
 * @Author Jsxs
 * @Date 2023/8/19 11:52
 * @PackageName:com.jsxs.aop
 * @ClassName: LogAspect
 * @Description: TODO
 * @Version 1.0
 */
@Aspect // 告诉IOC容器这是一个切面类 ⭐
public class LogAspect {
    // 1.抽取公共地切入点表达式  ⭐⭐
    @Pointcut("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void  pointCut(){}
    // 2.在目标方法之前运行切入:切入点表达式( public int com.jsxs.aop.MathCalculator.div(int,int))
    // *号代表这个类地所有方法, 一个.代表一个变量
    @Before("pointCut()")  ⭐⭐⭐
    public void logStart(){
        System.out.println("除法运行..... 参数列表是:{}");
    }
    // 3.在目标方法之后进行切入, 使用公共地切入点表达式
    @After("pointCut()")  ⭐⭐⭐⭐
    public void endStart(){
        System.out.println("除法运行结束....");
    }
    // 4.在目标方法返回正确地话
    @AfterReturning("pointCut()")  ⭐⭐⭐⭐⭐
    public void success(){
        System.out.println("除法正常运行... 运行结果:{}");
    }
    // 5.在目标方法出现异常地话
    @AfterThrowing("pointCut()")  ⭐⭐⭐⭐⭐⭐
    public void logError(){
        System.out.println("除法异常运行...");
    }
}
  1. 不使用公共切入点

标注是切面的注解,且使用四个通知方法

package com.jsxs.aop;
import org.aspectj.lang.annotation.*;
/**
 * @Author Jsxs
 * @Date 2023/8/19 11:52
 * @PackageName:com.jsxs.aop
 * @ClassName: LogAspect
 * @Description: TODO
 * @Version 1.0
 */
@Aspect // 告诉IOC容器这是一个切面类  ⭐
public class LogAspect {
    // 2.在目标方法之前运行切入:切入点表达式( public int com.jsxs.aop.MathCalculator.div(int,int)) 
    // *号代表这个类地所有方法, 一个.代表一个变量  ⭐⭐
    @Before("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void logStart(){
        System.out.println("除法运行..... 参数列表是:{}");
    }
    // 3.在目标方法之后进行切入, 使用公共地切入点表达式 ⭐⭐⭐
    @After("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void endStart(){
        System.out.println("除法运行结束....");
    }
    // 4.在目标方法返回正确地话  ⭐⭐⭐⭐
    @AfterReturning("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void success(){
        System.out.println("除法正常运行... 运行结果:{}");
    }
    // 5.在目标方法出现异常地话 ⭐⭐⭐⭐⭐
    @AfterThrowing("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void logError(){
        System.out.println("除法异常运行...");
    }
}
(4).编写配置类
  1. 注解版开启aop切面
package com.jsxs.config;
import com.jsxs.aop.LogAspect;
import com.jsxs.aop.MathCalculator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
 * @Author Jsxs
 * @Date 2023/8/19 11:41
 * @PackageName:com.jsxs.config
 * @ClassName: MainConfigOfAOP
 * @Description: TODO  AOP【动态代理】 : 指在程序运行期间动态的将某段代码切入到指定方法指定位置进行运行的编程方式;
 *                  1.如何使用?
 *                      (1).导入AOP的依赖。
 *                      (2).定义一个业务逻辑类(MathCalculator)。在业务逻辑运行的时候将日志进行打印(方法之前,方法结束,方法异常)
 *                      (3).定义一个日志切面类(LogAspect)。切面类里面的方法需要动态的感知 业务逻辑类(MathCalculator)的运行情况
 *                              (3.1).通知方法:  前置通知@Before(在目标方法运行之前运行),
 *                                              后置通知@After(在目标方法运行之后运行,不在意正常结束还是异常结束),
 *                                              返回通知@AfterReturning(在目标方法正常返回之后运行),
 *                                              异常通知@AfterThrowing(在目标方法发生异常之后运行),
 *                                              环绕通知@Round(动态代理,手动推进目标方法运行 joinPoint.)
 *                      (4).给切面类的目标方法标注何时何处地运行 (通知注解)⭐⭐
 *                      (5).将切面类和业务逻辑类(目标方法所在类) 都加入到容器中 ⭐⭐⭐
 *                      (6).必须告诉Spring的IOC容器哪个类是切面类(我们需要给切面类添加一个注解 @Aspect)  ⭐⭐⭐⭐
 *                      (7).在配置类上开启 注解版的切面功能 ( <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  @EnableAspectJAutoProxy)
 *                      (8).测试,这个逻辑类一定要使用IOC容器的类,不能使用new
 * @Version 1.0
 */
@Configuration  //⭐
@EnableAspectJAutoProxy //⭐⭐ 开启注解版本的依赖
public class MainConfigOfAOP {
    // 业务逻辑类  ⭐⭐⭐⭐
    @Bean
    public MathCalculator mathCalculator(){
        return new MathCalculator();
    }
    // 切面类 ⭐⭐⭐⭐⭐
    @Bean
    public LogAspect logAspect(){
        return new LogAspect();
    }
}
  1. 非注解版开启aop依赖

(5). 编写测试类
package com.jsxs.Test;
import com.jsxs.aop.MathCalculator;
import com.jsxs.config.MainConfigOfAOP;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
 * @Author Jsxs
 * @Date 2023/8/19 12:47
 * @PackageName:com.jsxs.Test
 * @ClassName: AOP_Test
 * @Description: TODO
 * @Version 1.0
 */
public class AOP_Test {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfAOP.class);
        for (String beanDefinitionName : applicationContext.getBeanDefinitionNames()) {
            System.out.println(beanDefinitionName);
        }
        // 1.这个对象我们不能使用new创建,我们需要使用IOC容器的组件进行调用 ⭐
        MathCalculator calculator = applicationContext.getBean(MathCalculator.class);
        calculator.div(1,3);
    }
}
  1. 测试结果 不写类名 和 结果

  1. 测试结果 写类名 和 结果

1.我们需要在切面类进行更改

JoinPoint 这个类如果要使用一定要写在参数列表的第一位,否则可能不生效

package com.jsxs.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import java.util.Arrays;
/**
 * @Author Jsxs
 * @Date 2023/8/19 11:52
 * @PackageName:com.jsxs.aop
 * @ClassName: LogAspect
 * @Description: TODO
 * @Version 1.0
 */
@Aspect // 告诉IOC容器这是一个切面类  ⭐
public class LogAspect {
    // 2.在目标方法之前运行切入:切入点表达式( public int com.jsxs.aop.MathCalculator.div(int,int))
    // *号代表这个类地所有方法, 一个.代表一个变量
    @Before("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void logStart(JoinPoint joinPoint){  //⭐⭐ 切入点类可以获取名字和参数列表
        System.out.println(joinPoint.getSignature().getName()+"除法运行..... 参数列表是:{"+ Arrays.asList(joinPoint.getArgs())+"}");
    }
    // 3.在目标方法之后进行切入, 使用公共地切入点表达式
    @After("execution(public int com.jsxs.aop.MathCalculator.*(..))")
    public void endStart(){
        System.out.println("除法运行结束....");
    }
    // 4.在目标方法返回正确地话  ⭐⭐⭐ 获取返回结果,注解里面的参数名要和方法里面的参数名一致
    @AfterReturning(value = "execution(public int com.jsxs.aop.MathCalculator.*(..))",returning = "result")
    public void success(JoinPoint joinPoint,Object result){
        System.out.println(joinPoint.getSignature().getName()+"除法正常运行... 运行结果:{"+result+"}");
    }
    // 5.在目标方法出现异常地话 ⭐⭐⭐⭐ 获取异常信息
    @AfterThrowing(value = "execution(public int com.jsxs.aop.MathCalculator.*(..))",throwing = "exception")
    public void logError(Exception exception){
        System.out.println("除法异常运行..."+exception);
    }
}

(二)、AOP 原理

  1. 看给容器中注册了什么组件?
  2. 这个组件什么时候工作?
  3. 这个组件工作时候的功能?

1.@EnableAspectJAutoProxy

(1).@EnableAspectJAutoProxy源码
*                 AOP【原理】
 *                  1.@EnableAspectJAutoProxy ->核心注解
 *                      (1).@Import(AspectJAutoProxyRegistrar.class) -> 给容器中导入AspectJAutoProxyRegistrar这个组件
 *                          internalAutoProxyCreator=AnnotationAwareAspectJAutoProxyCreator
 *                          给容器中注入了一个AnnotationAwareAspectJAutoProxyCreator ⭐

@EnableAspectJAutoProxy ->核心注解给容器中导入AspectJAutoProxyRegistrar这个组件

(2).AspectJAutoProxyRegistrar 自定义注册bean源码

通过这个类进行创建自定义组件

(3).打断点进行Debug测试
  1. registerBeanDefinitions 方法处打一个断点

  1. registerOrEscalateApcAsRequired()

  1. 给容器中注入AnnotationAwareAspectJAutoProxyCreator

2.AnnotationAwareAspectJAutoProxyCreator 分析

(1).继承树

CTRL+H 打开目录树

* AOP【原理】
 *                  1.@EnableAspectJAutoProxy ->核心注解
 *                      (1).@Import(AspectJAutoProxyRegistrar.class) -> 给容器中导入AspectJAutoProxyRegistrar这个组件
 *                          internalAutoProxyCreator=AnnotationAwareAspectJAutoProxyCreator
 *                          给容器中注入了一个AnnotationAwareAspectJAutoProxyCreator
 *                  2. AnnotationAwareAspectJAutoProxyCreator
 *                      AnnotationAwareAspectJAutoProxyCreator
 *                          ->(继承) AspectJAwareAdvisorAutoProxyCreator
 *                              ->(继承) AbstractAutoProxyCreator implements SmartInstantiationAwareBeanPostProcessor, BeanFactoryAware
 *                                       关注后置处理器(在bean初始化前后) 和 自动装配BeanFactory
 *                                       (2.1). setBeanFactory
 *                                  ->(继承) AbstractAdvisorAutoProxyCreator
 *                                      ->(继承) ProxyConfig
 *                                          ->(继承) Object       
(2).AbstractAutoProxyCreator

AbstractAutoProxyCreator类 具有后置处理器的逻辑

具有setBeanFactry()的功能

(3).AbstractAdvisorAutoProxyCreator

这里初始化了 initBeanFactory()

3.注册 AnnotationAwareAspectJAutoProxyCreator

(1).打断点进行Debug调试

1.打上第一个断点

2.配置类上打上两个断点

(2).运行流程 (创建和注册AnnotationAwareAspectJAutoProxyCreator)
*  3.流程:
 *                      (1).传入配置类,创建IOC容器 -> new AnnotationConfigApplicationContext(MainConfigOfAOP.class);
 *                      (2).注册配置类register(annotatedClasses),重启IOC容器refresh()
 *                      (3).registerBeanPostProcessors(beanFactory); 注册bean的后置处理器来方便拦截bean的创建
 *                          (3.1).先获取IOC容器已经定义了的需要创建对象的所有 BeanPostProcessor
 *                          (3.2).给容器中添加别的BeanPostProcessor
 *                          (3.3).优先注册了priorityOrderedPostProcessors接口的BeanPostProcessor
 *                          (3.4).在给容器中注册实现了Ordered接口的BeanPostProcessor
 *                          (3.5).注册没实现优先级接口的 BeanPostProcessors
 *                          (3.6).注册BeanPostProcessors,实际上就是创建BeanPostProcessors对象,保存在容器中;
 *                              创建internalAutoProxyCreator的BeanPostProcessors【AnnotationAwareAspectJAutoProxyCreator】
 *                                  (1).创建Bean的实列
 *                                  (2).populateBean:给bean的各种属性赋值
 *                                  (3).initializeBean: 初始化bean
 *                                      (1).invokeAwareMethods() :处理Aware接口的方法回调
 *                                      (2).applyBeanPostProcessorsBeforeInitialization() 应用后置处理器
 *                                      (3).invokeInitMethods()执行自定义的初始方法
 *                                      (4).applyBeanPostProcessorsAfterInitialization() 执行后置处理器的postProcessor
 *                                  (4).BeanPostProcessor(AnnotationAwareAspectJAutoProxyCreator) 创建成功
 *                         (3.7).把BeanPostProcessor注册到BeanFactory中 beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));

1.创建IOC容器

2.发现refresh()方法中具有 后置处理器的功能 注册配置类register(annotatedClasses),重启IOC容器refresh()

3.registerBeanPostProcessors(beanFactory); 注册bean的后置处理器来方便拦截bean的创建

3.1 先获取IOC容器已经定义了的需要创建对象的所有 BeanPostProcessor

3.2 给容器中添加别的BeanPostProcessor

3.3 优先注册了priorityOrderedPostProcessors接口的BeanPostProcessor

3.4 在给容器中注册实现了Ordered接口的BeanPostProcessor

3.5注册没实现优先级接口的 BeanPostProcessors

3.6 注册BeanPostProcessors,实际上就是创建BeanPostProcessors对象,保存在容器中;

4.AnnotationAwareAspectJAutoProxyCreator 执行时机

* 4.执行时机
 *                          1.遍历容器中所有的Bean,依次创建对象getBean(beanName)
 *                              getBean->doGetBean()->getSingleton->
 *                          2.创建bean
 *                              (1).先从缓存中获取当前bean,如果能获取到,说明bean是之前被创建过的,直接使用,否则再创建
 *                                  只要创建好的Bean都会被缓存起来。
 *
 *                              (2).CreateBean() 创建bean
 *                                  (2.1).resolveBeforeForeInstantion(beanName,mbdToUse) --> 希望后置处理器在此能返回一个代理对象,如果能返回代理对象就使用,如果不能就继续
 *                                  (2.2).doCreateBean() 真正的去创建一个bean实列
 *                           3.  AnnotationAwareAspectJAutoProxyCreator 在所有的bean创建之前会有一个拦截,InstantionAnwareBeanPostProcessor,会调用PostProcessBeforeInstantiation
 *

5.创建AOP代理对象

*  5.AOP原理
 *          1.每一个bean创建之前,调用postProcessBeforeInstantiation();
 *                              关心 普通组件 和 切面组件 的创建
 *                                  (1).判断当前bean是否在advisedBeans中(保存了所需要增强的bean)
 *                                  (2).判断是否是切面
 *                                  (3).是否需要跳过
 *                                      (3.1).获取候选的增强器(切面里面的通知方法) 每一个封装的通知方法都是一个增强器 ,返回true
 *                                      (3.2). 返回false -> 永远不跳过
 *          2.每一个bean创建之后,调用postProcessAfterInstantiation();
 *                              (1).获取当前bean的所有增强器(增强方法)
 *                                  (1.1).找到的候选的所有增强器(找那些通知方法是需要切入当前bean方法的)
 *                                  (1.2).获取能在当前bean使用的增强器
 *                                  (1.3).给增强器进行排序
 *                              (2).保存当前bean在adviseBeans中
 *                              (3).如果当前bean需要增强,创建当前bean的代理对象。
 *                                  (3.1).获取所有增强器(通知方法)
 *                                  (3.2).保存到proxyFactory
 *                                  (3.3).创建代理对象 ⭐ (两种)
 *                                      (3.3.1).JDKDynamicAopProxy(config)  ->jdk创建代理模式(有接口使用jdk)
 *                                      (3.3.2).ObjenesisCglibAopProxy(config)  ->cglib创建代理模式(无接口使用cglib)
 *                             ⭐      (3.4).给IOC容器返回当前组件使用cglib增强了的代理对象
 *                             ⭐      (3.5).以后容器中获取到的就是这个组件的代理对象,执行目标方法的时候,代理对象就会执行通知方法的流程

6.AOP原理的总结 ⭐

  1. @EnableAspectJAutoProxy 作用: 开启AOP注解功能
  2. @EnableAspectJAutoProxy 作用: 会给容器注册一个组件(AnnotationAwareAspectJAutoProxyCreator)
  3. AnnotationAwareAspectJAutoProxyCreator 是一个后置处理器
  4. 容器的创建流程
  • registerBeanPostProcessors(注册后置处理器),作用:创建registerBeanPostProcessors
  • finishBeanFactoryInitialization(beanFactory);作用:初始化剩下的单实列bean
  • 创建业务逻辑组件和切面组件
  • AnnotationAwareAspectJAutoProxyCreator 拦截组件的创建过程
  • 组件创建完之后,判断组件是否需要增强
  • 是: 切面的通知方法,包装成增强器(Adviros); 业务逻辑组件创建一个代理对象
  1. 执行目标方法
  • 代理对象执行目标方法
  • CglibAopProxy.intercept();
  • 得到目标方法的拦截器链 (增强器包装成拦截器MethodInterceptor)
  • 利用拦截器的链式机制,依次进入每一个拦截器进行执行
  • 效果:
  • 正常执行: 前置通知 -> 目标方法 -> 后置通知 -> 返回通知
  • 出现异常: 前置通知 ->目标方法 -> 后置通知 -> 异常通知

相关实践学习
通过日志服务实现云资源OSS的安全审计
本实验介绍如何通过日志服务实现云资源OSS的安全审计。
相关文章
|
17天前
|
缓存 监控 Java
SpringBoot @Scheduled 注解详解
使用`@Scheduled`注解实现方法周期性执行,支持固定间隔、延迟或Cron表达式触发,基于Spring Task,适用于日志清理、数据同步等定时任务场景。需启用`@EnableScheduling`,注意线程阻塞与分布式重复问题,推荐结合`@Async`异步处理,提升任务调度效率。
332 128
|
1月前
|
XML 安全 Java
使用 Spring 的 @Aspect 和 @Pointcut 注解简化面向方面的编程 (AOP)
面向方面编程(AOP)通过分离横切关注点,如日志、安全和事务,提升代码模块化与可维护性。Spring 提供了对 AOP 的强大支持,核心注解 `@Aspect` 和 `@Pointcut` 使得定义切面与切入点变得简洁直观。`@Aspect` 标记切面类,集中处理通用逻辑;`@Pointcut` 则通过表达式定义通知的应用位置,提高代码可读性与复用性。二者结合,使开发者能清晰划分业务逻辑与辅助功能,简化维护并提升系统灵活性。Spring AOP 借助代理机制实现运行时织入,与 Spring 容器无缝集成,支持依赖注入与声明式配置,是构建清晰、高内聚应用的理想选择。
297 0
|
1月前
|
Java 测试技术 API
将 Spring 的 @Embedded 和 @Embeddable 注解与 JPA 结合使用的指南
Spring的@Embedded和@Embeddable注解简化了JPA中复杂对象的管理,允许将对象直接嵌入实体,减少冗余表与连接操作,提升数据库设计效率。本文详解其用法、优势及适用场景。
221 126
|
18天前
|
XML Java 数据格式
常用SpringBoot注解汇总与用法说明
这些注解的使用和组合是Spring Boot快速开发和微服务实现的基础,通过它们,可以有效地指导Spring容器进行类发现、自动装配、配置、代理和管理等核心功能。开发者应当根据项目实际需求,运用这些注解来优化代码结构和服务逻辑。
141 12
|
1月前
|
Java 测试技术 数据库
使用Spring的@Retryable注解进行自动重试
在现代软件开发中,容错性和弹性至关重要。Spring框架提供的`@Retryable`注解为处理瞬时故障提供了一种声明式、可配置的重试机制,使开发者能够以简洁的方式增强应用的自我恢复能力。本文深入解析了`@Retryable`的使用方法及其参数配置,并结合`@Recover`实现失败回退策略,帮助构建更健壮、可靠的应用程序。
131 1
使用Spring的@Retryable注解进行自动重试
|
1月前
|
传感器 Java 数据库
探索Spring Boot的@Conditional注解的上下文配置
Spring Boot 的 `@Conditional` 注解可根据不同条件动态控制 Bean 的加载,提升应用的灵活性与可配置性。本文深入解析其用法与优势,并结合实例展示如何通过自定义条件类实现环境适配的智能配置。
探索Spring Boot的@Conditional注解的上下文配置
|
1月前
|
智能设计 Java 测试技术
Spring中最大化@Lazy注解,实现资源高效利用
本文深入探讨了 Spring 框架中的 `@Lazy` 注解,介绍了其在资源管理和性能优化中的作用。通过延迟初始化 Bean,`@Lazy` 可显著提升应用启动速度,合理利用系统资源,并增强对 Bean 生命周期的控制。文章还分析了 `@Lazy` 的工作机制、使用场景、最佳实践以及常见陷阱与解决方案,帮助开发者更高效地构建可扩展、高性能的 Spring 应用程序。
Spring中最大化@Lazy注解,实现资源高效利用
|
1月前
|
安全 IDE Java
Spring 的@FieldDefaults和@Data:Lombok 注解以实现更简洁的代码
本文介绍了如何在 Spring 应用程序中使用 Project Lombok 的 `@Data` 和 `@FieldDefaults` 注解来减少样板代码,提升代码可读性和可维护性,并探讨了其适用场景与限制。
Spring 的@FieldDefaults和@Data:Lombok 注解以实现更简洁的代码
|
1月前
|
缓存 监控 安全
Spring Boot 的执行器注解:@Endpoint、@ReadOperation 等
Spring Boot Actuator 提供多种生产就绪功能,帮助开发者监控和管理应用。通过注解如 `@Endpoint`、`@ReadOperation` 等,可轻松创建自定义端点,实现健康检查、指标收集、环境信息查看等功能,提升应用的可观测性与可管理性。
Spring Boot 的执行器注解:@Endpoint、@ReadOperation 等