当前位置: 首页 > article >正文

Spring的AOP的JoinPoint和ProceedingJoinPoint

Spring的AOP的JoinPoint

在Spring AOP中,JoinPoint 是一个核心接口,用于表示程序执行过程中的一个连接点(如方法调用或异常抛出)。它提供了访问当前被拦截方法的关键信息的能力。以下是关于 JoinPoint 的详细说明:


一、JoinPoint 的作用

JoinPoint 主要用于在切面(Aspect)中获取被拦截方法的上下文信息,例如:

  • 被拦截的方法(Method 对象)
  • 方法所属的目标对象(Target Object)
  • 方法的参数列表
  • 方法签名(方法名、返回类型、参数类型等)

二、JoinPoint 的核心方法

JoinPoint 接口定义了以下常用方法:

方法说明
getArgs()返回被拦截方法的参数数组(Object[])。
getTarget()返回目标对象(即被代理的原始对象)。
getSignature()返回方法签名(MethodSignature 对象),包含方法名、返回类型等信息。
getThis()返回代理对象本身(AOP 动态生成的代理类实例)。
toString()返回连接点的字符串描述(如方法全限定名)。

三、ProceedingJoinPoint(环绕通知专用)

ProceedingJoinPointJoinPoint 的子接口,仅在 @Around 环绕通知中使用。它新增了 proceed() 方法,用于控制目标方法的执行:

方法说明
proceed()执行目标方法,并返回其返回值(原始调用)。
proceed(Object[] args)使用修改后的参数执行目标方法(可改变参数后再调用)。

四、代码示例

1. 使用 JoinPoint 记录方法信息
@Aspect
@Component
public class LoggingAspect {

    @Before("execution(* com.example.service.*.*(..))")
    public void logMethodStart(JoinPoint joinPoint) {
        // 获取方法签名
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        String methodName = signature.getMethod().getName();
        String className = signature.getDeclaringTypeName();

        // 获取方法参数
        Object[] args = joinPoint.getArgs();
        System.out.println("方法调用: " + className + "." + methodName);
        System.out.println("参数列表: " + Arrays.toString(args));
    }
}
2. 使用 ProceedingJoinPoint 实现环绕通知
@Aspect
@Component
public class TimingAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();
        
        // 执行目标方法(可修改参数)
        Object result = joinPoint.proceed();

        long endTime = System.currentTimeMillis();
        System.out.println("方法执行耗时: " + (endTime - startTime) + "ms");
        return result;
    }
}

五、常见应用场景

  1. 日志记录
    记录方法调用信息、参数、返回值或异常。

    @AfterThrowing(pointcut = "execution(* com.example.service.*.*(..))", throwing = "ex")
    public void logException(JoinPoint joinPoint, Exception ex) {
        System.out.println("方法抛出异常: " + ex.getMessage());
    }
    
  2. 性能监控
    统计方法执行耗时。

    @Around("execution(* com.example.service.*.*(..))")
    public Object trackPerformance(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.nanoTime();
        Object result = pjp.proceed();
        long duration = System.nanoTime() - start;
        System.out.println("方法耗时: " + duration + "纳秒");
        return result;
    }
    
  3. 参数校验
    在方法执行前验证参数合法性。

    @Before("execution(* com.example.service.UserService.createUser(..))")
    public void validateUser(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        String username = (String) args[0];
        if (username == null || username.isEmpty()) {
            throw new IllegalArgumentException("用户名不能为空!");
        }
    }
    

六、注意事项

  1. 仅支持方法级别拦截
    Spring AOP 的 JoinPoint 仅适用于方法调用,无法拦截字段访问或构造器调用(需使用 AspectJ)。

  2. 代理对象的限制
    getThis() 返回的是代理对象,而非原始对象。若需访问原始对象,可通过 getTarget()

  3. 性能开销
    频繁操作 JoinPoint 或复杂的切面逻辑可能影响性能,需合理设计。


总结

JoinPoint 是 Spring AOP 中获取被拦截方法上下文信息的关键接口,而 ProceedingJoinPoint 在环绕通知中用于控制方法执行流程。通过合理使用这些接口,可以实现日志、监控、校验等横切关注点,提升代码的可维护性。















JoinPoint 是 Spring AOP 中的一个核心接口,它提供了对连接点(Join Point)的访问能力。连接点是指程序执行过程中明确的点,比如方法调用或异常处理等。通过 JoinPoint 接口,可以在通知(Advice)中获取关于当前连接点的信息,如方法签名、参数列表、目标对象等。

主要功能

  • 提供对连接点的静态信息访问:包括方法签名、目标对象等。
  • 不支持控制连接点的执行流程:这意味着你不能决定是否继续执行目标方法或者修改其返回值。如果你需要这种能力,应该使用 ProceedingJoinPoint

常见用途

  • 日志记录:记录方法调用的详细信息,如方法名、参数等。
  • 性能监控:虽然不能直接用于测量方法执行时间(这通常需要使用 @AroundProceedingJoinPoint),但可以用于记录方法开始和结束的时间戳。
  • 安全检查:在方法执行之前进行一些权限检查或其他验证。

使用示例

以下是一些具体的使用场景和代码示例:

1. 获取方法签名
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    @After("execution(* com.example.service.*.*(..))")
    public void logMethodCall(JoinPoint joinPoint) {
        System.out.println("方法签名: " + joinPoint.getSignature());
    }
}
2. 获取方法参数
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ParameterLoggingAspect {

    @Before("execution(* com.example.service.*.*(..))")
    public void logMethodParameters(JoinPoint joinPoint) {
        System.out.println("方法名: " + joinPoint.getSignature().getName());
        for (Object arg : joinPoint.getArgs()) {
            System.out.println("参数: " + arg);
        }
    }
}
3. 获取目标对象
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TargetObjectLoggingAspect {

    @AfterReturning(pointcut = "execution(* com.example.service.*.*(..))", returning = "result")
    public void logTargetObject(JoinPoint joinPoint, Object result) {
        System.out.println("目标对象: " + joinPoint.getTarget());
        System.out.println("方法返回值: " + result);
    }
}

关键方法

  • getSignature():返回一个 Signature 对象,包含有关连接点的签名信息,如方法名、参数类型等。
  • getArgs():返回一个 Object[] 数组,包含传递给目标方法的所有参数。
  • getTarget():返回目标对象实例。
  • getThis():返回代理对象实例。

注意事项

  • 性能影响:频繁地从 JoinPoint 获取信息可能会带来一定的性能开销,尤其是在高并发环境下。因此,应仅在必要时使用这些信息。
  • 不可改变执行流程JoinPoint 不允许你控制或改变连接点的执行流程。如果你需要这样的功能,例如在环绕通知中决定是否执行目标方法或修改其返回值,那么你应该使用 ProceedingJoinPoint

通过合理利用 JoinPoint,可以让你的切面逻辑更加灵活和强大,同时保持良好的模块化和清晰的关注点分离。这对于实现横切关注点如日志记录、安全性检查等功能非常有用。














在Spring框架的面向切面编程(AOP)中,JoinPoint是一个核心接口,它封装了连接点(即程序执行过程中的某个特定点,如方法调用或异常抛出)的信息。当AOP框架拦截到一个连接点时,它会创建一个JoinPoint对象,并将该对象传递给相应的通知(Advice)。通知可以通过JoinPoint对象获取被拦截方法的相关信息,如方法签名、参数列表、目标对象等。

以下是JoinPoint接口的一些关键方法和属性(注意:实际的方法和属性可能因Spring版本而异,但以下是一些常见的):

  1. 获取方法签名

    • Signature getSignature(): 返回被拦截方法的签名。这通常是一个MethodSignature对象,可以通过它获取方法的名称、返回类型、参数类型等信息。
  2. 获取参数

    • Object[] getArgs(): 返回被拦截方法的参数列表。注意,这些参数是原始对象,如果需要修改参数值,通常需要使用AspectJProceedingJoinPoint(它扩展了JoinPoint)并通过其proceed(Object[] args)方法传递新的参数数组。但在标准的Spring AOP中,直接修改参数值是不支持的。
  3. 获取目标对象

    • Object getTarget(): 返回被代理的目标对象。这是被拦截方法实际所属的对象。
  4. 获取代理对象

    • Object getThis(): 返回代理对象。在大多数情况下,这与getTarget()返回的对象不同,特别是在使用JDK动态代理时。
  5. 获取类型信息

    • Class<?> getTargetType(): 返回目标对象的类。这通常与getTarget().getClass()返回的结果相同,但提供了在不需要实际目标对象的情况下获取类型信息的能力。
  6. 获取AOP代理类型

    • boolean isStaticPart(): 如果当前JoinPoint表示的是一个静态连接点(在Spring AOP中通常不是这种情况),则返回true。在大多数情况下,这个方法会返回false

需要注意的是,JoinPoint对象在AOP通知中是以参数的形式传递的。例如,在@Before@AfterReturning@AfterThrowing@After注解的方法中,你可以通过添加一个JoinPoint类型的参数来访问连接点的信息。然而,在@Around注解的方法中,你通常会使用ProceedingJoinPoint类型(它是JoinPoint的子接口)的参数,因为它提供了额外的proceed()方法来控制目标方法的执行。

最后,需要强调的是,虽然JoinPoint提供了访问连接点信息的强大能力,但在AOP通知中过度使用这些信息可能会导致代码难以理解和维护。因此,建议仅在必要时使用JoinPoint,并尽量保持AOP通知的简洁和专注。














Spring AOP 中 JoinPoint 的概念

在面向切面编程(AOP)中,Joinpoint 表示应用程序执行过程中某个特定的时间点或位置,在这个时间点上可以插入额外的行为。对于 Spring AOP 而言,理解并利用好 Joinpoint 对于实现横切关注点至关重要。

具体来说,Joinpoint 可能是指方法调用、异常抛出事件或者其他类型的程序操作。然而,在实际应用中,Spring AOP 主要支持的是方法级别的连接点,即只允许在方法执行前后加入增强处理逻辑。

JoinPoint 接口的主要属性和方法

ProceedingJoinPointJoinPoint 的子接口之一,提供了更多的功能以便更灵活地控制目标对象的方法执行流程:

  • proceed(): 执行当前的目标方法,并返回其结果;如果该方法声明会抛出异常,则此函数也会传播这些异常。

  • getArgs(): 获取传递给目标方法的实际参数列表。

  • getSignature(): 返回描述正在被执行的方法签名的对象。

  • getTarget(): 得到代理实例所指向的真实业务类对象。

  • getThis(): 当前织入建议的 this 引用,通常就是代理本身。

实际案例展示如何使用 JoinPoint

下面是一个简单的例子展示了如何定义切入点以及围绕它编写前置通知(pre-notification),这里假设有一个名为 MyService 的服务组件,其中包含了若干个业务方法。

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class LoggingAspect {

    @Before("execution(* com.example.service.MyService.*(..))")
    public void logMethodCall(JoinPoint joinPoint){
        System.out.println("The method " + joinPoint.getSignature().getName()
                           +" is called with arguments "+ Arrays.toString(joinPoint.getArgs()));
    }
}

上述代码片段创建了一个方面(aspect),每当任何来自 com.example.service.MyService 类的方法被调用时都会触发日志记录动作。通过传入 JoinPoint 参数可以获得关于此次调用的具体信息,比如方法名及其输入参数等。








在Spring的AOP(面向切面编程)中,JoinPoint是一个核心概念,它代表了程序执行过程中的一个特定点,比如方法的执行或者异常的抛出。在AOP术语中,JoinPoint通常被理解为一个连接点,它是切面(Aspect)可以插入增强处理(Advice)的地方。
具体来说,JoinPoint封装了关于一个被增强方法的信息,比如方法的签名、参数等。当Spring AOP框架执行到某个JoinPoint时,它会检查是否有切面在该点定义了增强处理。如果有,那么它会执行相应的增强处理逻辑。
在Spring AOP中,JoinPoint通常通过ProceedingJoinPoint的接口来提供,这个接口除了包含JoinPoint的功能外,还增加了一个proceed()方法,允许增强处理在执行目标方法之前或之后,甚至是在目标方法执行过程中插入自定义逻辑。
总的来说,JoinPoint是Spring AOP实现增强处理的关键概念,它使得开发者能够在不修改原有业务逻辑代码的情况下,向程序中添加额外的行为。
















Spring的AOP的ProceedingJoinPoint

在 Spring AOP 中,ProceedingJoinPointJoinPoint 的子接口,专用于 环绕通知(@Around。它提供了控制目标方法执行流程的能力,允许开发者在方法执行前后插入自定义逻辑,甚至可以修改参数、返回值或阻止方法执行。以下是其核心用法和实际场景的详细说明:


一、ProceedingJoinPoint 的核心作用

ProceedingJoinPoint 在环绕通知中扮演“流程控制器”的角色,主要功能包括:

  1. 执行目标方法:通过 proceed() 触发目标方法的执行。
  2. 修改方法参数:传递自定义参数数组给目标方法。
  3. 捕获方法返回值/异常:处理目标方法的返回结果或拦截异常。

二、核心方法

ProceedingJoinPoint 新增了以下关键方法:

方法说明
Object proceed()执行目标方法,并返回其原始返回值。
Object proceed(Object[] args)使用修改后的参数数组执行目标方法(可动态调整参数)。

三、代码示例

1. 基本用法:方法执行计时
@Aspect
@Component
public class TimingAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object measureTime(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        
        // 执行目标方法,并获取返回值
        Object result = pjp.proceed(); 
        
        long end = System.currentTimeMillis();
        System.out.println("方法执行耗时: " + (end - start) + "ms");
        return result;
    }
}
2. 修改方法参数
@Aspect
@Component
public class ParamModificationAspect {

    @Around("execution(* com.example.service.UserService.updateUser(..))")
    public Object sanitizeInput(ProceedingJoinPoint pjp) throws Throwable {
        // 获取原始参数
        Object[] args = pjp.getArgs();
        String username = (String) args[0];
        
        // 参数处理:去除空格
        String sanitizedUsername = username.trim();
        args[0] = sanitizedUsername;
        
        // 使用修改后的参数执行目标方法
        return pjp.proceed(args);
    }
}
3. 异常处理与重试机制
@Aspect
@Component
public class RetryAspect {

    @Around("execution(* com.example.service.PaymentService.processPayment(..))")
    public Object retryOnFailure(ProceedingJoinPoint pjp) throws Throwable {
        int maxRetries = 3;
        int attempts = 0;
        Throwable lastException = null;

        while (attempts < maxRetries) {
            try {
                return pjp.proceed();
            } catch (Exception e) {
                lastException = e;
                attempts++;
                System.out.println("第 " + attempts + " 次重试...");
            }
        }
        throw new RuntimeException("操作失败,已重试 " + maxRetries + " 次", lastException);
    }
}

四、常见应用场景

1. 性能监控

统计方法执行时间,识别性能瓶颈。

@Around("execution(* com.example.api.*.*(..))")
public Object monitorPerformance(ProceedingJoinPoint pjp) throws Throwable {
    long start = System.nanoTime();
    Object result = pjp.proceed();
    long duration = System.nanoTime() - start;
    MetricsCollector.record(pjp.getSignature().getName(), duration);
    return result;
}
2. 缓存管理

在方法执行前检查缓存,未命中时执行方法并缓存结果。

@Around("@annotation(cacheable)")
public Object handleCache(ProceedingJoinPoint pjp, Cacheable cacheable) throws Throwable {
    String cacheKey = generateCacheKey(pjp);
    Object cachedValue = cache.get(cacheKey);
    if (cachedValue != null) {
        return cachedValue;
    }
    Object result = pjp.proceed();
    cache.put(cacheKey, result, cacheable.ttl());
    return result;
}
3. 事务管理

手动控制事务的提交与回滚(Spring 通常通过 @Transactional 实现,此处为示例)。

@Around("execution(* com.example.service.OrderService.placeOrder(..))")
public Object manageTransaction(ProceedingJoinPoint pjp) throws Throwable {
    TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {
        Object result = pjp.proceed();
        transactionManager.commit(status);
        return result;
    } catch (Exception e) {
        transactionManager.rollback(status);
        throw e;
    }
}

五、注意事项

  1. 必须调用 proceed()
    @Around 通知中,若不调用 proceed(),目标方法将不会执行。

  2. 参数类型安全
    修改参数时需确保类型匹配,避免 ClassCastException

  3. 避免无限递归
    若切面拦截的方法内部又调用了其他被同一切面拦截的方法,需谨慎设计切点表达式。

  4. 性能影响
    复杂的环绕逻辑可能增加方法执行开销,需权衡功能与性能。


六、与其他通知的对比

通知类型是否使用 ProceedingJoinPoint能否控制方法执行
@Around
@Before❌(使用 JoinPoint
@After❌(使用 JoinPoint
@AfterReturning❌(使用 JoinPoint
@AfterThrowing❌(使用 JoinPoint

总结

ProceedingJoinPoint 是 Spring AOP 中功能最强大的通知类型接口,适用于需要 完全控制目标方法执行流程 的场景。通过合理使用,可以实现缓存、重试、事务、监控等高级功能,但需注意其执行顺序和性能影响。








ProceedingJoinPoint 是 Spring AOP 中的一个特殊接口,它扩展了 JoinPoint 接口,并提供了控制目标方法执行的能力。这意味着你可以通过 ProceedingJoinPoint 来决定是否以及如何执行目标方法。这个接口主要用于环绕通知(@Around Advice),允许你在目标方法执行之前和之后执行自定义逻辑,并且可以控制目标方法的执行流程。

主要功能

  • 继承了 JoinPoint 的所有功能:包括获取方法签名、参数列表、目标对象等信息。
  • 提供对目标方法执行的控制:通过调用 proceed() 方法来触发目标方法的执行,这使得你可以在目标方法执行前后添加额外的逻辑,甚至可以完全跳过目标方法的执行。

关键方法

  • proceed():触发目标方法的执行。此方法可以抛出 Throwable,因此通常需要在声明中处理异常。如果目标方法有返回值,则该方法将返回目标方法的结果。
  • proceed(Object[] args):允许你使用不同的参数列表来调用目标方法。这对于动态修改传递给目标方法的参数非常有用。

使用场景

  • 性能监控:测量方法执行时间。
  • 事务管理:在方法执行前后开启或提交事务。
  • 缓存机制:检查缓存以避免重复计算。
  • 日志记录:不仅记录方法调用,还可以记录方法执行结果或耗时。

示例代码

下面是一个使用 ProceedingJoinPoint 实现的方法执行时间测量示例:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PerformanceMonitorAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();

        // 调用目标方法
        Object proceed = joinPoint.proceed();

        long executionTime = System.currentTimeMillis() - start;
        System.out.println(joinPoint.getSignature() + " 执行时间: " + executionTime + "ms");

        return proceed; // 返回目标方法的结果
    }
}

在这个例子中:

  • @Around 注解用于指定一个切入点表达式,匹配 com.example.service 包下的所有方法。
  • ProceedingJoinPoint 对象作为参数传入到环绕通知方法中,允许我们调用 proceed() 方法来执行目标方法。
  • 在目标方法执行前后分别记录时间戳,然后计算并打印出方法的执行时间。

修改目标方法的参数或返回值

你还可以使用 ProceedingJoinPoint 来修改目标方法的参数或返回值:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ModifyReturnValueAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object modifyReturnValue(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed(); // 执行目标方法

        // 假设目标方法返回一个字符串,我们可以在此基础上进行修改
        if (result instanceof String) {
            result = ((String) result).toUpperCase();
        }

        return result; // 返回修改后的结果
    }
}

这里展示了如何在目标方法执行后修改其返回值。

总结

ProceedingJoinPoint 提供了一种强大的方式来控制和增强目标方法的行为,适用于需要精确控制方法执行流程的场景。与 JoinPoint 相比,它的主要优势在于能够通过 proceed() 方法显式地触发目标方法的执行,并能灵活地处理方法的参数和返回值。这使得它成为实现复杂切面逻辑的理想选择,如性能监控、事务管理和缓存等。








在Spring框架的面向切面编程(AOP)中,ProceedingJoinPoint是一个关键的接口,它扩展了JoinPoint接口,并提供了控制目标方法执行流程的能力。以下是关于ProceedingJoinPoint的详细解释:

一、定义与功能

ProceedingJoinPoint代表了一个正在执行的连接点,即目标方法执行时的特定点。当一个切面(Aspect)被应用到一个目标方法上时,ProceedingJoinPoint提供了一种方式来访问目标方法的参数、拦截目标方法的执行,并在需要时控制目标方法的执行流程。

二、主要功能

  1. 获取目标方法的信息

    • 通过ProceedingJoinPoint,可以获取目标方法的签名(包括方法名、参数类型等)、参数值、所在的类等信息。这对于在切面中进行日志记录、性能监控等操作非常有用。
  2. 拦截目标方法的执行

    • ProceedingJoinPoint允许切面拦截目标方法的执行。在环绕通知(Around Advice)中,可以在目标方法执行之前和之后执行额外的逻辑。
  3. 控制目标方法的执行流程

    • 除了拦截目标方法的执行外,ProceedingJoinPoint还可以控制目标方法的执行流程。例如,可以在环绕通知中根据特定的条件决定是否执行目标方法,或者在目标方法执行前后执行不同的逻辑分支。
  4. 执行目标方法

    • 通过调用ProceedingJoinPointproceed()方法,可以继续执行被拦截的目标方法。如果目标方法成功执行,proceed()方法会返回目标方法的执行结果;如果目标方法抛出异常,proceed()方法也会抛出相应的异常。

三、使用场景

ProceedingJoinPoint主要用于环绕通知中,因为环绕通知需要在目标方法执行前后执行额外的逻辑,并且可以控制目标方法的执行流程。以下是一些典型的使用场景:

  • 日志记录:在目标方法执行前后记录日志,包括方法的名称、参数值、执行时间等信息。
  • 性能监控:在目标方法执行前后记录执行时间,以便进行性能监控和优化。
  • 事务管理:在目标方法执行前后开启和提交事务,确保数据的一致性。
  • 安全检查:在目标方法执行前进行安全检查,确保用户具有执行该方法的权限。

四、示例代码

以下是一个使用环绕通知和ProceedingJoinPoint的示例代码:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LoggingAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object logMethodExecution(ProceedingJoinPoint joinPoint) throws Throwable {
        // 记录方法开始执行的日志
        System.out.println("Before method execution: " + joinPoint.getSignature());
        try {
            // 执行目标方法
            Object result = joinPoint.proceed();
            // 记录方法执行成功的日志
            System.out.println("After method execution: " + joinPoint.getSignature());
            return result;
        } catch (Exception e) {
            // 记录方法执行失败的日志
            System.out.println("Error in method execution: " + joinPoint.getSignature());
            throw e;
        }
    }
}

在这个示例中,LoggingAspect类定义了一个环绕通知,它会在目标方法执行前后记录日志。在通知方法中,通过ProceedingJoinPoint可以获取目标方法的信息,并使用proceed()方法来执行目标方法。

综上所述,ProceedingJoinPoint是Spring AOP中一个重要的接口,它提供了强大的功能来拦截和控制目标方法的执行。通过ProceedingJoinPoint,可以获取目标方法的信息、拦截目标方法的执行、控制目标方法的执行流程,并在目标方法执行前后执行额外的逻辑。这使得切面能够更加灵活地实现横切关注点,提高代码的可维护性和可扩展性。








Spring AOP 中 ProceedingJoinPoint 的使用方法

方法签名与继承关系

ProceedingJoinPointJoinPoint 接口的一个子接口,在其基础上增加了 proceed() 方法。此方法对于实现环绕通知至关重要,因为它允许控制目标方法的执行流程。

public interface ProceedingJoinPoint extends JoinPoint {
    Object proceed() throws Throwable;
}
环绕通知的工作原理

通过 @Around 注解可以定义环绕通知逻辑。在该类型的增强处理中,可以在调用实际业务逻辑前后加入额外的操作。具体来说:

  • 调用 proceed() 前的部分相当于前置通知;
  • proceed() 返回后的部分则对应于后置通知;

这使得开发者能够在不修改原有代码的情况下灵活地增加功能或改变行为模式。

示例代码展示

下面是一个简单的例子来说明如何利用 ProceedingJoinPoint 实现环绕通知的功能:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LoggingAspect {

    @Around("execution(* com.example.service..*(..))")
    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();

        try {
            // 执行被拦截的方法并返回结果
            return joinPoint.proceed();
        } finally {
            long elapsedTime = System.currentTimeMillis() - start;
            System.out.println(joinPoint.getSignature().getName() + " executed in " + elapsedTime + "ms");
        }
    }
}

在此案例里,每当匹配到指定包下的任何公共成员函数被执行时,都会触发上述方面内的日志记录操作。它不仅会在每次调用前打印出开始时间戳,还会计算整个过程耗时并在完成后输出相关信息。








Spring的AOP(面向切面编程)中的ProceedingJoinPoint是JoinPoint的子接口,它代表了一个可执行的连接点,比如一个方法的执行。与JoinPoint不同的是,ProceedingJoinPoint允许控制一个连接点(比如方法调用)的执行,可以选择继续执行或者中断执行。
在Spring AOP中,当你编写一个环绕通知(Around Advice)时,你会接收到一个ProceedingJoinPoint类型的参数。通过这个参数,你可以决定是否继续执行连接点的方法,或者中断执行并抛出异常。
使用ProceedingJoinPoint的常见场景包括:
一、前置通知:在目标方法执行之前执行一些逻辑。
二、后置通知:在目标方法执行之后执行一些逻辑(无论目标方法是否成功执行)。
三、环绕通知:在目标方法执行前后执行一些逻辑,并决定是否继续执行目标方法或中断执行。
四、异常通知:当目标方法抛出异常时执行一些逻辑。
在环绕通知中,你可以通过调用ProceedingJoinPoint的proceed()方法来继续执行目标方法。如果你选择不调用proceed()方法,则目标方法不会被执行。
例如:
public Object myAroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
// 在目标方法执行之前的逻辑
System.out.println(“Before proceeding”);
try {
// 继续执行目标方法
Object result = joinPoint.proceed();
// 在目标方法执行之后的逻辑
System.out.println(“After proceeding”);
return result;
} catch (Throwable e) {
// 处理异常
System.out.println(“Exception occurred”);
throw e;
}
}
在这个例子中,myAroundAdvice是一个环绕通知,它接收一个ProceedingJoinPoint类型的参数。在调用proceed()方法之前,可以执行一些前置逻辑;在调用proceed()方法之后,可以执行一些后置逻辑。如果目标方法抛出异常,则可以在catch块中处理异常。
















Spring的AOP的JoinPoint和ProceedingJoinPoint的区别

在Spring AOP中,JoinPointProceedingJoinPoint是两个核心接口,它们的主要区别体现在功能用途使用场景上。以下是详细的对比说明:


1. 定义与关系

接口说明
JoinPointAOP中所有连接点(如方法调用)的通用接口,提供连接点的基本信息(方法、参数、目标对象等)。
ProceedingJoinPointJoinPoint的子接口,专用于@Around环绕通知,增加了对目标方法执行流程的控制能力(如proceed())。

2. 核心功能对比

功能JoinPointProceedingJoinPoint
获取连接点信息✔️ 支持(如方法名、参数、目标对象、注解等)✔️ 完全继承JoinPoint的功能
控制目标方法执行❌ 无法控制目标方法执行流程✔️ 核心功能:通过proceed()方法执行目标方法(或下一个切面),并可以修改参数、返回值或捕获异常。
适用通知类型@Before@After@AfterReturning@AfterThrowing仅限@Around
是否必须调用proceed()不涉及✔️ 必须显式调用proceed(),否则目标方法不会执行(类似责任链模式,需手动触发后续逻辑)。

3. 使用场景示例

(1) JoinPoint的典型用途

在非环绕通知(如@Before@After)中获取方法信息:

@Before("execution(* com.example.service.*.*(..))")
public void logBefore(JoinPoint joinPoint) {
    String methodName = joinPoint.getSignature().getName();
    Object[] args = joinPoint.getArgs();
    System.out.println("Method " + methodName + " called with args: " + Arrays.toString(args));
}
(2) ProceedingJoinPoint的典型用途

@Around通知中控制目标方法执行,并统计耗时:

@Around("execution(* com.example.service.*.*(..))")
public Object measureTime(ProceedingJoinPoint pjp) throws Throwable {
    long start = System.currentTimeMillis();
    // 可修改参数(可选)
    Object[] modifiedArgs = modifyArgs(pjp.getArgs());
    // 执行目标方法(必须调用proceed())
    Object result = pjp.proceed(modifiedArgs);
    long end = System.currentTimeMillis();
    System.out.println("Method executed in " + (end - start) + "ms");
    // 可修改返回值(可选)
    return modifyResult(result);
}

4. 关键差异总结

特性JoinPointProceedingJoinPoint
能否控制目标方法执行❌ 不能✔️ 能(通过proceed()
能否修改参数或返回值❌ 只能获取,不能修改✔️ 能(通过修改proceed()的参数,或处理返回值)
是否支持异常捕获与处理❌ 只能通过@AfterThrowing捕获异常✔️ 能(通过try-catch包裹proceed(),直接处理异常)
是否依赖调用proceed()不涉及✔️ 必须调用,否则目标方法或后续切面不会执行

5. 注意事项

  1. @Around必须使用ProceedingJoinPoint
    如果尝试在@Around通知中使用JoinPoint,将无法调用proceed(),导致目标方法不执行。

  2. proceed()的返回值与参数

    • 可以修改参数:pjp.proceed(modifiedArgs);
    • 可以修改返回值:return process(result);
  3. 异常处理灵活性
    @Around中,可通过try-catch捕获目标方法的异常并决定是否继续抛出:

    try {
        return pjp.proceed();
    } catch (Exception e) {
        // 自定义异常处理逻辑
        throw new CustomException("Wrapped exception", e);
    }
    
  4. 性能监控与事务控制
    @Around结合ProceedingJoinPoint常用于需要完整控制目标方法执行的场景,如:

    • 方法耗时统计
    • 事务管理(开启、提交、回滚)
    • 缓存逻辑(先查缓存,未命中再执行目标方法)

6. 总结

  • JoinPoint:提供连接点的只读信息,适用于非环绕通知(@Before@After等)。
  • ProceedingJoinPoint:在@Around控制目标方法执行流程,支持参数修改、返回值处理和异常捕获。

正确区分二者的用途,是灵活使用Spring AOP的关键!















在 Spring AOP 中,JoinPointProceedingJoinPoint 是两个重要的接口,它们用于在切面(Aspect)中获取关于连接点(Join Point)的信息或控制连接点的行为。尽管它们有一些相似之处,但也有显著的区别。

JoinPoint

JoinPoint 接口提供了访问当前连接点的静态信息的能力,例如方法签名和目标对象。它通常作为参数传递给通知方法(Advice),以便在这些方法内部使用。但是,它不允许你控制或改变连接点的执行流程。

主要功能
  • 提供对连接点的访问:包括方法签名、目标对象等。
  • 无法控制连接点的执行:这意味着你不能决定是否继续执行目标方法或者修改其返回值。
使用示例
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LoggingAspect {

    @After("execution(* com.example.service.*.*(..))")
    public void logMethodCall(JoinPoint joinPoint) {
        System.out.println("方法名: " + joinPoint.getSignature().getName());
        System.out.println("目标对象: " + joinPoint.getTarget());
    }
}

在这个例子中,JoinPoint 被用来获取并打印当前执行的方法名称和目标对象的信息。

ProceedingJoinPoint

ProceedingJoinPoint 继承自 JoinPoint,并且额外提供了 proceed() 方法。这个方法允许你在环绕通知(@Around Advice)中显式地控制目标方法的执行。也就是说,你可以决定是否以及何时调用目标方法,并且可以获取或修改它的返回值。

主要功能
  • 继承了 JoinPoint 的所有功能:可以访问连接点的所有静态信息。
  • 控制连接点的执行:通过 proceed() 方法来调用目标方法,还可以选择不调用它以完全绕过目标方法的执行。
  • 获取和修改返回值:可以在调用 proceed() 后获取目标方法的返回值,并对其进行修改。
使用示例
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PerformanceAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();

        // 调用目标方法
        Object proceed = joinPoint.proceed();

        long executionTime = System.currentTimeMillis() - start;
        System.out.println(joinPoint.getSignature() + " 执行时间: " + executionTime + "ms");

        return proceed; // 可以在这里修改返回值
    }
}

在这个例子中,ProceedingJoinPoint 被用来测量一个方法的执行时间。注意 proceed() 方法的调用是必需的,否则目标方法不会被执行。

总结

  • JoinPoint 提供了访问连接点静态信息的能力,但无法控制连接点的执行过程。
  • ProceedingJoinPoint 除了包含 JoinPoint 的所有功能外,还允许你通过 proceed() 方法来控制目标方法的执行,这使得它非常适合于实现环绕通知。

根据你的需求选择合适的接口类型:如果你只需要记录日志或其他不需要干预正常流程的操作,那么 JoinPoint 就足够了;如果你想进行性能监控、事务管理或者其他需要控制方法执行流程的操作,则应该使用 ProceedingJoinPoint















在Spring框架的面向切面编程(AOP)中,JoinPoint和ProceedingJoinPoint是两个核心接口,它们在AOP通知中扮演着关键角色,但具有不同的功能和用途。以下是两者的主要区别:

一、定义与功能

  1. JoinPoint

    • 定义:JoinPoint代表程序执行过程中可被拦截的特定点,如方法调用或异常抛出。AOP框架通过拦截这些点来插入额外的逻辑,实现横切关注点的功能。
    • 功能:主要用于获取被拦截方法的相关信息,如方法名、参数值、目标对象等。这些信息对于实现日志记录、性能监控、安全检查等横切关注点至关重要。
  2. ProceedingJoinPoint

    • 定义:ProceedingJoinPoint在JoinPoint的基础上提供了额外的能力,允许在通知中控制方法的执行流程。它主要用于环绕通知(Around Advice),因为环绕通知需要在目标方法执行前后执行额外的逻辑,并且可以决定是否继续执行目标方法。
    • 功能:除了提供JoinPoint的所有功能外,还增加了一个重要的方法proceed()。通过调用proceed()方法,可以继续执行被拦截的方法,或者在某些条件下选择不执行该方法。这种能力在实现复杂的AOP通知时非常有用。

二、使用场景

  1. JoinPoint

    • 主要用于获取被拦截方法的相关信息,并基于这些信息执行额外的逻辑。例如,在日志记录的通知中,可以通过JoinPoint获取被调用方法的名称和参数值,从而在日志中记录这些信息。
    • 通常用于@Before、@AfterReturning、@After、@AfterThrowing这四个注解的方法上。
  2. ProceedingJoinPoint

    • 主要用于环绕通知中,通过控制目标方法的执行流程来实现复杂的业务逻辑。例如,可以在一个权限检查的通知中,根据用户的权限决定是否执行某个方法。
    • 在环绕通知中,必须调用proceed()方法来继续执行被通知的方法,否则被通知的方法将不会执行。

三、接口关系

  • ProceedingJoinPoint接口继承自JoinPoint接口,因此它包含了JoinPoint的所有方法和功能,并增加了proceed()方法以控制方法的执行流程。

综上所述,JoinPoint和ProceedingJoinPoint在Spring AOP中扮演着不同的角色,具有不同的功能和用途。JoinPoint主要用于获取被拦截方法的信息,而ProceedingJoinPoint则在此基础上提供了控制方法执行流程的能力。在实际应用中,开发人员需要根据具体的需求选择合适的接口来实现横切关注点的功能。















Spring AOP中的JoinPoint和ProceedingJoinPoint是两个核心接口,它们在AOP通知中扮演着关键角色,但存在明显的区别。
JoinPoint接口代表了程序执行过程中可以被拦截的特定点,这些点通常包括方法调用、异常抛出等。通过JoinPoint,开发者可以获取到当前被拦截的方法的信息,如方法名、参数值、目标对象等。这为在通知中添加额外的逻辑提供了基础。JoinPoint接口提供了多种方法用于获取被拦截方法的各种信息,例如:
getSignature():返回一个Signature对象,表示被拦截的方法签名。通过Signature对象,可以获取方法的名称、返回类型、参数类型等信息。
getArgs():返回一个数组,包含被拦截方法的所有参数值。
getTarget():返回被拦截方法的目标对象,即方法所属的类的实例。
getThis():返回当前AOP代理对象,通常与getTarget()返回的对象相同,但在某些情况下可能不同。
ProceedingJoinPoint接口则是JoinPoint接口的一个扩展,它专门用于环绕通知(Around Advice)。除了提供JoinPoint的所有功能外,ProceedingJoinPoint接口还增加了一个重要的方法:proceed()。这个方法允许在通知中控制目标方法的执行流程。通过调用proceed()方法,可以继续执行被拦截的方法,或者在某些条件下选择不执行该方法。这种能力在实现复杂的AOP通知时非常有用。
总结来说,JoinPoint和ProceedingJoinPoint的主要区别在于它们在AOP通知中的使用方式和功能:JoinPoint主要用于获取被拦截方法的相关信息,而ProceedingJoinPoint则在此基础上提供了控制方法执行流程的能力。这使得ProceedingJoinPoint在环绕通知中非常有用,而JoinPoint则更广泛地应用于各种AOP通知类型中。
















Spring的AOP的JoinPoint和ProceedingJoinPoint的getSignature()方法

在Spring AOP(面向切面编程)中,JoinPointProceedingJoinPoint接口都提供了getSignature()方法,用于获取被拦截方法的签名信息。尽管这两个接口在功能上有所差异(特别是ProceedingJoinPoint提供了控制目标方法执行的能力),但它们在获取方法签名方面有着共同之处。

JoinPoint.getSignature()

  • 返回值Signature
  • 描述:返回当前连接点(即被拦截的方法调用)的签名。这个签名是一个通用的表示,可以是方法签名、构造器签名等。在大多数情况下,对于Spring AOP来说,这个签名会是一个MethodSignature实例,因为它主要拦截的是方法调用。
  • 用途:通过返回的Signature对象,可以获取被拦截方法的名称、参数类型、返回类型等信息。这对于日志记录、安全检查、事务管理等横切关注点非常有用。

ProceedingJoinPoint.getSignature()

  • 返回值Signature(与JoinPoint.getSignature()相同)
  • 描述:在ProceedingJoinPoint接口中,getSignature()方法的行为与JoinPoint中的相同。它也返回当前连接点的签名,通常是一个MethodSignature实例。
  • 特殊之处:虽然ProceedingJoinPoint扩展了JoinPoint并提供了额外的功能(如控制目标方法的执行),但在获取方法签名方面,它并没有引入新的行为或信息。因此,ProceedingJoinPoint.getSignature()的用途与JoinPoint.getSignature()完全相同。

使用示例

以下是一个简单的示例,展示了如何在环绕通知中使用ProceedingJoinPoint.getSignature()来获取被拦截方法的签名信息:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

@Aspect
public class MyAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object logMethodSignature(ProceedingJoinPoint joinPoint) throws Throwable {
        // 获取方法签名
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        
        // 输出方法信息
        System.out.println("Method name: " + signature.getName());
        System.out.println("Return type: " + signature.getReturnType().getName());
        System.out.println("Parameter types: " + Arrays.toString(signature.getParameterTypes()));
        
        // 执行目标方法
        Object result = joinPoint.proceed();
        
        return result;
    }
}

在这个示例中,MyAspect类定义了一个环绕通知,它拦截了com.example.service包下所有类的所有方法调用。在通知方法中,通过joinPoint.getSignature()获取了被拦截方法的签名,并将其转换为MethodSignature类型,以便访问方法的名称、返回类型和参数类型等信息。然后,它输出了这些信息,并执行了目标方法。

总之,JoinPoint.getSignature()ProceedingJoinPoint.getSignature()都用于获取被拦截方法的签名信息,尽管它们在所属的接口和提供的功能上有所不同。在Spring AOP中,这两个方法通常返回的是MethodSignature实例,因为它主要处理的是方法调用连接点。








在 Spring AOP 中,JoinPointProceedingJoinPoint 都提供了对连接点(Join Point)的访问功能。这两个接口都包含了一个名为 getSignature() 的方法,该方法返回一个 Signature 对象,这个对象包含了关于被拦截方法的元数据信息。

Signature 接口

Signature 接口提供了一些方法来获取有关连接点的详细信息,主要包括:

  • toShortString():返回简短的签名表示形式。
  • toLongString():返回详细的签名表示形式。
  • toString():返回默认格式的签名字符串。
  • getName():返回方法名。
  • getDeclaringTypeName():返回声明该方法的类名。
  • getModifiers():返回方法的修饰符(如 public, private 等)。

JoinPoint 和 ProceedingJoinPoint 的 getSignature() 方法

尽管 JoinPointProceedingJoinPoint 都继承了相同的 getSignature() 方法,但它们的主要区别在于是否能够控制目标方法的执行流程。然而,在获取方法签名方面,两者的行为是相同的。

使用示例

下面通过几个简单的例子展示如何使用 getSignature() 方法来获取有关被拦截方法的信息。

示例 1: 使用 JoinPoint 获取方法签名
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    @After("execution(* com.example.service.*.*(..))")
    public void logMethodCallDetails(JoinPoint joinPoint) {
        var signature = joinPoint.getSignature();
        System.out.println("方法名: " + signature.getName());
        System.out.println("所属类名: " + signature.getDeclaringTypeName());
        System.out.println("方法修饰符: " + signature.getModifiers());
        System.out.println("完整描述: " + signature.toLongString());
    }
}

在这个例子中,我们定义了一个切面,它会在匹配的方法调用后记录一些基本的方法签名信息。

示例 2: 使用 ProceedingJoinPoint 获取方法签名

虽然 ProceedingJoinPoint 主要用于环绕通知(@Around Advice),但它同样可以用来获取方法签名信息:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PerformanceMonitorAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        var signature = joinPoint.getSignature();
        System.out.println("正在测量方法: " + signature.getName() + " 的执行时间");

        long start = System.currentTimeMillis();
        Object proceed = joinPoint.proceed(); // 执行目标方法
        long executionTime = System.currentTimeMillis() - start;

        System.out.println(signature.getName() + " 执行完成,耗时: " + executionTime + "ms");
        
        return proceed; // 返回目标方法的结果
    }
}

这里不仅展示了如何获取方法签名信息,还演示了如何利用 ProceedingJoinPoint 控制目标方法的执行,并测量其执行时间。

总结

  • getSignature() 方法无论是在 JoinPoint 还是 ProceedingJoinPoint 中,都可以用来获取当前连接点的方法签名信息。
  • 这个方法返回的是一个实现了 Signature 接口的对象,通过它可以访问到关于方法的各种元数据,如方法名、所属类名等。
  • 在实际应用中,getSignature() 常用于日志记录、性能监控等场景,帮助开发者更好地理解应用程序的运行情况和行为模式。

通过这些信息,开发者可以在不侵入业务代码的前提下,实现诸如日志记录、权限验证、性能监控等多种横切关注点的功能。








在Spring的AOP(面向切面编程)中,JoinPointProceedingJoinPoint 是两个重要的接口,它们都提供了 getSignature() 方法。下面详细介绍这两个接口以及该方法的使用。

1. JoinPoint 接口

JoinPoint 是Spring AOP中的一个核心接口,它代表了程序执行过程中的一个连接点,比如方法调用、异常抛出等。在前置通知、后置通知、环绕通知等各种通知类型中,都可以通过 JoinPoint 对象获取连接点的相关信息。

getSignature() 方法

getSignature() 方法用于获取当前连接点的静态签名信息,返回一个 Signature 对象。Signature 对象包含了方法的名称、参数类型等信息。

示例代码

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    @Before("execution(* com.example.service.*.*(..))")
    public void beforeMethod(JoinPoint joinPoint) {
        // 获取方法签名
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        // 获取方法名称
        String methodName = signature.getName();
        // 获取方法参数类型
        Class<?>[] parameterTypes = signature.getParameterTypes();

        System.out.println("Before method: " + methodName);
        System.out.print("Parameter types: ");
        for (Class<?> paramType : parameterTypes) {
            System.out.print(paramType.getName() + " ");
        }
        System.out.println();
    }
}

在上述代码中,@Before 注解定义了一个前置通知,在目标方法执行之前执行。通过 joinPoint.getSignature() 方法获取方法签名,然后将其转换为 MethodSignature 对象,进而获取方法名称和参数类型。

2. ProceedingJoinPoint 接口

ProceedingJoinPointJoinPoint 的子接口,它只在环绕通知中使用。环绕通知可以在目标方法执行前后进行增强,并且可以控制目标方法是否执行。

getSignature() 方法

ProceedingJoinPointgetSignature() 方法与 JoinPointgetSignature() 方法功能相同,都是用于获取当前连接点的静态签名信息。

示例代码

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PerformanceAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
        // 获取方法签名
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        String methodName = signature.getName();

        long startTime = System.currentTimeMillis();
        // 执行目标方法
        Object result = pjp.proceed();
        long endTime = System.currentTimeMillis();

        System.out.println("Method " + methodName + " executed in " + (endTime - startTime) + " ms");
        return result;
    }
}

在上述代码中,@Around 注解定义了一个环绕通知。通过 pjp.getSignature() 方法获取方法签名,然后将其转换为 MethodSignature 对象,进而获取方法名称。在目标方法执行前后记录时间,计算方法的执行时间。

总结

  • JoinPointProceedingJoinPointgetSignature() 方法都用于获取当前连接点的静态签名信息。
  • JoinPoint 可用于前置通知、后置通知等各种通知类型,而 ProceedingJoinPoint 仅用于环绕通知。
  • 通过 getSignature() 方法返回的 Signature 对象,可以获取方法的名称、参数类型等信息。








在Spring AOP中,JoinPoint 和 ProceedingJoinPoint 是两个重要的接口,它们都提供了 getSignature() 方法,用于获取被拦截方法的签名信息。

  • JoinPoint.getSignature()
    返回值:返回一个 Signature 对象,表示被拦截的方法签名。
    作用:通过 Signature 对象,可以获取方法的名称、返回类型、参数类型等信息。
    示例:
@Before("execution(* com.example.service.*.*(..))")
public void beforeAdvice(JoinPoint joinPoint) {
    Signature signature = joinPoint.getSignature();
    System.out.println("Method name: " + signature.getName());
    System.out.println("Declaring type: " + signature.getDeclaringTypeName());
}
  • ProceedingJoinPoint.getSignature()
    返回值:同样返回一个 Signature 对象。
    作用:与 JoinPoint.getSignature() 的功能一致,用于获取被拦截方法的签名信息。
    示例:
@Around("execution(* com.example.service.*.*(..))")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
    Signature signature = joinPoint.getSignature();
    System.out.println("Method name: " + signature.getName());
    Object result = joinPoint.proceed();
    return result;
}
  • Signature 接口
    Signature 接口提供了多种方法来获取方法签名的详细信息,例如:
    getName():获取方法名。
    getDeclaringType():获取方法所属的类。
    getDeclaringTypeName():获取方法所属类的名称。
    toString()、toShortString()、toLongString():分别获取方法签名的完整字符串、简短字符串和详细字符串。
    区别
    JoinPoint 是AOP中最基本的接口,适用于所有通知类型(如@Before、@After等),而ProceedingJoinPoint 是JoinPoint的子接口,仅用于环绕通知(@Around),并且提供了proceed()方法。
    ProceedingJoinPoint 的 proceed() 方法允许在通知中控制目标方法的执行流程。
    在实际使用中,可以根据通知类型选择合适的接口来获取方法签名信息。








在Spring的AOP(面向切面编程)中,JoinPoint和ProceedingJoinPoint是两个重要的接口,它们提供了对当前连接点(如方法执行)的访问。这两个接口都有一个getSignature()方法,用于获取当前连接点的签名信息。
JoinPoint接口的getSignature()方法返回一个Signature对象,该对象代表了被增强方法的签名。Signature是一个标记接口,通常实现为MethodSignature(针对方法)或其他类型(针对其他类型的连接点,如构造器)。通过MethodSignature,你可以获取到方法的名称、参数类型、返回类型等信息。
ProceedingJoinPoint是JoinPoint的子接口,它提供了对环绕通知(around advice)的支持。在环绕通知中,你不仅可以获取到连接点的信息,还可以控制连接点的执行(如决定是否继续执行、是否抛出异常等)。ProceedingJoinPoint的getSignature()方法与JoinPoint的相同,也是返回一个代表被增强方法签名的Signature对象。
需要注意的是,虽然JoinPoint和ProceedingJoinPoint都提供了getSignature()方法,但在实际使用中,它们的应用场景有所不同。JoinPoint通常用于前置通知(before advice)、后置通知(after returning advice)和异常通知(after throwing advice)中,而ProceedingJoinPoint则专门用于环绕通知中。
















org.aspectj.lang.Signature

org.aspectj.lang.Signature 是 AspectJ 框架中的一个接口,它用于表示方法、构造器、字段或任何其他程序元素的签名。这个接口提供了一系列方法,允许你获取关于签名的各种信息。以下是对 org.aspectj.lang.Signature 的详细解释:

一、主要方法

  1. toString():返回此签名的缩写字符串表示形式。
  2. toShortString():返回此签名的扩展字符串表示形式。
  3. getName():返回此签名的标识符部分。对于方法,这将返回方法名称。
  4. getModifiers():返回表示为 int 的此签名上的修饰符。可以使用 java.lang.reflect.Modifier 上定义的常量和辅助方法来操作这些修饰符。
  5. getDeclaringType():返回一个 java.lang.Class 对象,表示声明此成员的类、接口或方面。对于成员内声明,这将是声明成员的类型。
  6. getDeclaringTypeName():返回声明类型的完全限定名称。这等效于调用 getDeclaringType().getName(),但可能是为了更高的效率而缓存了结果。

二、使用场景

在 AspectJ 的面向切面编程(AOP)中,Signature 接口通常与 JoinPoint 接口一起使用。JoinPoint 表示连接点,即在程序执行过程中能够插入切面的点(如方法调用或异常抛出)。通过 JoinPointgetSignature() 方法,你可以获取到当前连接点的签名,进而使用 Signature 接口提供的方法来获取签名的详细信息。

三、示例代码

以下是一个使用 Signature 接口的示例代码,它展示了如何在前置通知中获取并打印方法签名的信息:

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Aspect
public class LoggingAspect {

    private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);

    @Before("execution(* com.example..*(..))")
    public void logBefore(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        logger.info("Method signature: {}", signature.toShortString());
        logger.info("Declaring type: {}", signature.getDeclaringType().getName());
        logger.info("Method name: {}", signature.getName());
        // 可以根据需要添加更多日志信息
    }
}

在这个示例中,我们定义了一个名为 LoggingAspect 的切面,它包含一个前置通知 logBefore。这个通知会在匹配到指定切入点表达式(这里是 execution(* com.example..*(..)),表示 com.example 包及其子包中的所有方法)时执行。在通知内部,我们通过 JoinPoint 获取到当前连接点的签名,并使用 Signature 接口的方法打印了签名的相关信息。

四、总结

org.aspectj.lang.Signature 是 AspectJ 框架中一个重要的接口,它提供了获取方法、构造器、字段等程序元素签名信息的方法。在 AOP 编程中,这个接口通常与 JoinPoint 接口一起使用,以在连接点处获取并处理签名的详细信息。








org.aspectj.lang.Signature 是 AspectJ 提供的一个接口,用于表示连接点(Join Point)处的方法或构造函数的签名信息。通过 Signature 接口,你可以获取关于被拦截方法或构造函数的各种元数据,如名称、所属类型、参数类型等。这个接口在 Spring AOP 中同样适用,因为 Spring AOP 基于 AspectJ 的注解进行实现。

Signature 接口的主要方法

以下是 Signature 接口中一些常用的方法:

  • String toShortString():返回一个简短的字符串表示形式,通常包含方法名和参数类型。
  • String toLongString():返回详细的字符串表示形式,包括更多细节如修饰符、返回类型等。
  • String toString():返回默认格式的签名字符串,通常是方法声明的简化版本。
  • String getName():返回方法或构造函数的名字。
  • String getDeclaringTypeName():返回声明该方法或构造函数的类的全限定名。
  • int getModifiers():返回方法或构造函数的修饰符(如 public, private 等),可以通过 java.lang.reflect.Modifier 类来解释这些修饰符的具体含义。
  • Class<?> getDeclaringType()(仅适用于某些实现):返回声明该方法或构造函数的类对象。

使用示例

下面是一些具体的使用示例,展示了如何在 Spring AOP 切面中利用 Signature 获取相关信息。

示例 1: 使用 JoinPoint 获取并打印方法签名信息
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {

    @AfterReturning("execution(* com.example.service.*.*(..))")
    public void logMethodCallDetails(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        
        System.out.println("方法名: " + signature.getName());
        System.out.println("所属类名: " + signature.getDeclaringTypeName());
        System.out.println("完整描述: " + signature.toLongString());
        System.out.println("简短描述: " + signature.toShortString());
    }
}

在这个例子中,我们定义了一个切面,它会在匹配的方法调用后记录一些基本的方法签名信息,包括方法名、所属类名以及详细和简短的签名描述。

示例 2: 结合 ProceedingJoinPoint 进行性能监控

虽然 ProceedingJoinPoint 主要用于环绕通知(@Around Advice),但它同样可以用来获取方法签名信息,并且可以在方法执行前后添加额外的逻辑,例如测量方法执行时间。

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PerformanceMonitorAspect {

    @Around("execution(* com.example.service.*.*(..))")
    public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        Signature signature = joinPoint.getSignature();
        System.out.println("正在测量方法: " + signature.getName() + " 的执行时间");

        long start = System.currentTimeMillis();
        Object proceed = joinPoint.proceed(); // 执行目标方法
        long executionTime = System.currentTimeMillis() - start;

        System.out.println(signature.getName() + " 执行完成,耗时: " + executionTime + "ms");
        
        return proceed; // 返回目标方法的结果
    }
}

此示例不仅展示了如何获取方法签名信息,还演示了如何利用 ProceedingJoinPoint 控制目标方法的执行,并测量其执行时间。

总结

  • Signature 接口提供了丰富的功能来获取方法或构造函数的元数据信息,这对于日志记录、性能监控等场景非常有用。
  • 在 Spring AOP 中,无论是使用 JoinPoint 还是 ProceedingJoinPoint,都可以通过 getSignature() 方法获得当前连接点的 Signature 对象,从而访问到相关的方法签名信息。
  • 合理利用这些信息可以帮助开发者更好地理解应用程序的行为,提高代码的可维护性和调试效率。








org.aspectj.lang.Signature 是 AspectJ 框架中的一个接口,在 Spring AOP(基于 AspectJ 实现)里发挥着重要作用,它主要用于表示程序中连接点(如方法调用、构造函数调用等)的静态签名信息。下面详细介绍这个接口。

接口作用

在 AOP 编程中,当切面代码切入到目标对象的某个连接点时,需要获取该连接点的相关静态信息,例如方法名、参数类型等,Signature 接口就是用来提供这些信息的。

主要方法

String getName()
  • 功能:获取签名所代表的方法、构造函数或类型的名称。
  • 示例
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SignatureExampleAspect {
    @Before("execution(* com.example.service.*.*(..))")
    public void beforeAdvice(JoinPoint joinPoint) {
        String name = joinPoint.getSignature().getName();
        System.out.println("Method name: " + name);
    }
}

在上述代码中,通过 joinPoint.getSignature().getName() 可以获取到目标方法的名称。

String toLongString()
  • 功能:返回签名的完整详细字符串表示,包含完整的类名、方法名、参数类型等信息。
  • 示例
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LongStringExampleAspect {
    @Before("execution(* com.example.service.*.*(..))")
    public void beforeAdvice(JoinPoint joinPoint) {
        String longString = joinPoint.getSignature().toLongString();
        System.out.println("Long signature: " + longString);
    }
}
String toShortString()
  • 功能:返回签名的简短字符串表示,通常只包含关键信息,相对简洁。
  • 示例
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ShortStringExampleAspect {
    @Before("execution(* com.example.service.*.*(..))")
    public void beforeAdvice(JoinPoint joinPoint) {
        String shortString = joinPoint.getSignature().toShortString();
        System.out.println("Short signature: " + shortString);
    }
}
String toString()
  • 功能:返回签名的默认字符串表示,其格式介于 toLongString()toShortString() 之间,提供了比较适中的信息展示。
  • 示例
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ToStringExampleAspect {
    @Before("execution(* com.example.service.*.*(..))")
    public void beforeAdvice(JoinPoint joinPoint) {
        String string = joinPoint.getSignature().toString();
        System.out.println("Signature as string: " + string);
    }
}

子接口

Signature 有几个重要的子接口,在实际使用中更具针对性:

  • MethodSignature:用于表示方法签名,通过它可以获取方法的返回类型、参数类型等更详细的方法相关信息。
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MethodSignatureExampleAspect {
    @Before("execution(* com.example.service.*.*(..))")
    public void beforeAdvice(JoinPoint joinPoint) {
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Class<?> returnType = methodSignature.getReturnType();
        System.out.println("Method return type: " + returnType.getName());
    }
}
  • ConstructorSignature:用于表示构造函数签名,可以获取构造函数的相关信息。

总结

org.aspectj.lang.Signature 接口及其子接口为 AOP 编程提供了强大的连接点静态信息获取能力,开发者可以根据具体需求从签名中提取所需的方法、构造函数等相关信息,从而实现灵活的切面编程。








org.aspectj.lang.Signature 是 AspectJ 框架中的一个接口,用于表示一个连接点(Join Point)的签名信息。在 Spring AOP 中,Signature 接口的实现类通常用于描述被拦截方法的相关信息。以下是关于 org.aspectj.lang.Signature 的详细介绍:

  1. 接口定义
    org.aspectj.lang.Signature 是一个接口,定义了获取连接点签名信息的方法。它是一个通用的接口,适用于各种连接点(如方法调用、字段访问等)。在 Spring AOP 中,最常见的连接点是方法调用,因此 Signature 接口的实现类通常用于描述方法的签名信息。

  2. 主要方法
    Signature 接口提供了以下方法来获取签名信息:

    • String getName()
      功能:获取签名的名称。
      返回值:对于方法签名,返回方法的名称;对于字段签名,返回字段的名称。
      示例:
    Signature signature = joinPoint.getSignature();
    System.out.println("Name: " + signature.getName());
    
    • String getDeclaringTypeName()
      功能:获取签名所属的类的名称。
      返回值:返回签名所在的类的完全限定名(包括包名)。
      示例:
    Signature signature = joinPoint.getSignature();
    System.out.println("Declaring Type: " + signature.getDeclaringTypeName());
    
    • String toShortString()
      功能:获取签名的简短字符串表示形式。
      返回值:返回一个简短的字符串,通常包含方法名和参数类型(但不包括返回类型)。
      示例:
    Signature signature = joinPoint.getSignature();
    System.out.println("Short String: " + signature.toShortString());
    
    • String toString()
      功能:获取签名的完整字符串表示形式。
      返回值:返回一个完整的字符串,包含方法的返回类型、名称和参数类型。
      示例:
    Signature signature = joinPoint.getSignature();
    System.out.println("Full String: " + signature.toString());
    
    • String toLongString()
      功能:获取签名的详细字符串表示形式。
      返回值:返回一个更详细的字符串,包含方法的返回类型、名称、参数类型和修饰符。
      示例:
    Signature signature = joinPoint.getSignature();
    System.out.println("Long String: " + signature.toLongString());
    
  3. 实现类
    在 Spring AOP 中,Signature 接口的常见实现类是 MethodSignature,它专门用于描述方法的签名信息。MethodSignature 提供了更多方法来获取方法的详细信息,例如:
    getMethod():返回 java.lang.reflect.Method 对象,表示被拦截的方法。
    getParameterNames():返回方法参数的名称数组(需要在编译时启用调试信息)。
    getParameterTypes():返回方法参数的类型数组。

  4. 示例代码
    以下是一个完整的示例,展示如何在 Spring AOP 中使用 JoinPoint 和 Signature:

    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.Signature;
    import org.springframework.stereotype.Component;
    
    @Aspect
    @Component
    public class LoggingAspect {
    
        @Before("execution(* com.example.service.*.*(..))")
        public void beforeAdvice(JoinPoint joinPoint) {
            // 获取签名信息
            Signature signature = joinPoint.getSignature();
            
            // 打印方法名称
            System.out.println("Method name: " + signature.getName());
            
            // 打印方法所属类的名称
            System.out.println("Declaring type: " + signature.getDeclaringTypeName());
            
            // 打印方法的简短字符串表示
            System.out.println("Short String: " + signature.toShortString());
            
            // 打印方法的完整字符串表示
            System.out.println("Full String: " + signature.toString());
            
            // 打印方法的详细字符串表示
            System.out.println("Long String: " + signature.toLongString());
        }
    }
    
  5. 总结
    org.aspectj.lang.Signature 是一个用于描述连接点签名信息的接口,它提供了多种方法来获取签名的详细信息。在 Spring AOP 中,Signature 接口的实现类(如 MethodSignature)被广泛用于获取被拦截方法的相关信息,从而实现更灵活的切面逻辑。








org.aspectj.lang.Signature 是 AspectJ 编程语言中的一个接口,它代表了程序元素(如方法、构造函数、字段等)的签名。这个接口在 AspectJ 的面向切面编程(AOP)框架中被广泛使用,以支持切面(Aspect)与程序其他部分之间的连接点(Join Point)匹配。
Signature 接口提供了获取签名相关信息的方法,例如获取签名的字符串表示、获取被签名元素所属的类名等。这些方法使得切面能够基于方法的名称、参数类型、返回类型等条件来匹配连接点,从而实现切面逻辑与业务逻辑的解耦。
在 AspectJ 中,Signature 接口通常与其他 AOP 相关的接口和注解一起使用,如 JoinPoint、Pointcut、Advice 等。通过这些接口和注解,开发者可以灵活地定义切面、指定切点、编写增强逻辑,从而实现对程序行为的拦截和修改。
需要注意的是,org.aspectj.lang.Signature 是 AspectJ 框架的一部分,因此要使用它,需要在项目中引入 AspectJ 的相关依赖,并配置好 AOP 的运行环境。








org.aspectj.lang.Signature 是 Spring AOP 和 AspectJ 中的一个核心接口,用于表示连接点(Join Point)的签名信息。它提供了对目标方法、构造函数或字段的元数据访问能力,通常用于在切面中获取目标方法的名称、参数类型、返回类型等信息。


1. Signature 的作用

Signature 接口主要用于在切面中获取以下信息:

  • 目标方法的名称。
  • 目标方法的返回类型。
  • 目标方法所在的类或接口。
  • 目标方法的修饰符(如 publicprivate 等)。
  • 目标方法的参数类型。

通过这些信息,可以在切面中实现更精细的逻辑控制,例如根据方法名或参数类型动态决定是否执行某些操作。


2. Signature 的主要实现类

Signature 是一个接口,其具体实现类包括:

  • MethodSignature:表示方法的签名,提供了对方法元数据的访问。
  • ConstructorSignature:表示构造函数的签名。
  • FieldSignature:表示字段的签名。

在实际使用中,MethodSignature 是最常用的实现类。


3. Signature 的核心方法

Signature 接口定义了以下常用方法:

方法说明
String getName()获取目标方法、构造函数或字段的名称。
Class getDeclaringType()获取声明目标方法、构造函数或字段的类或接口。
int getModifiers()获取目标方法、构造函数或字段的修饰符(如 publicprivate 等)。
String toLongString()返回完整的签名信息(包括修饰符、返回类型、方法名、参数类型等)。
String toShortString()返回简短的签名信息(通常只包含方法名)。
String toString()返回默认格式的签名信息。

4. MethodSignature 的扩展方法

MethodSignatureSignature 的子接口,专门用于表示方法的签名。它提供了以下额外的方法:

方法说明
Class getReturnType()获取目标方法的返回类型。
Class[] getParameterTypes()获取目标方法的参数类型数组。
Class[] getExceptionTypes()获取目标方法声明的异常类型数组。

5. 使用示例

以下是一个使用 SignatureMethodSignature 的示例,展示如何在切面中获取目标方法的详细信息:

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

@Aspect
@Component
public class LoggingAspect {

    @Before("execution(* com.example.service.*.*(..))")
    public void logMethodDetails(JoinPoint joinPoint) {
        // 获取 Signature 对象
        Signature signature = joinPoint.getSignature();

        // 输出方法的基本信息
        System.out.println("Method Name: " + signature.getName());
        System.out.println("Declaring Type: " + signature.getDeclaringTypeName());
        System.out.println("Modifiers: " + Modifier.toString(signature.getModifiers()));
        System.out.println("Signature: " + signature.toLongString());

        // 如果 Signature 是 MethodSignature,可以进一步获取方法的具体信息
        if (signature instanceof MethodSignature) {
            MethodSignature methodSignature = (MethodSignature) signature;
            System.out.println("Return Type: " + methodSignature.getReturnType().getName());

            Class<?>[] parameterTypes = methodSignature.getParameterTypes();
            System.out.println("Parameter Types: " + Arrays.toString(parameterTypes));
        }
    }
}

6. 输出示例

假设目标方法是 com.example.service.UserService.createUser(String name, int age),上述切面的输出可能如下:

Method Name: createUser
Declaring Type: com.example.service.UserService
Modifiers: public
Signature: public void com.example.service.UserService.createUser(String, int)
Return Type: void
Parameter Types: [class java.lang.String, int]

7. 常见应用场景

  • 日志记录:记录方法的名称、参数和返回类型。
  • 权限校验:根据方法名或参数动态判断是否有权限执行。
  • 性能监控:结合 @AroundProceedingJoinPoint,统计方法的执行时间。
  • 动态代理:根据方法签名决定是否执行某些逻辑。

8. 总结

  • Signature 是 Spring AOP 和 AspectJ 中用于表示连接点签名的接口。
  • MethodSignature 是其子接口,专门用于表示方法的签名,提供了更多方法元数据的访问能力。
  • 通过 SignatureMethodSignature,可以在切面中获取目标方法的详细信息,实现更灵活的逻辑控制。

掌握 Signature 的使用,是深入理解 Spring AOP 的关键之一!
















http://www.kler.cn/a/527412.html

相关文章:

  • java求职学习day23
  • golang面试题
  • electron 应用开发实践
  • unity学习22:Application类其他功能
  • 「AI学习笔记」深度学习的起源与发展:从神经网络到大数据(二)
  • 探索AI(chatgpt、文心一言、kimi等)提示词的奥秘
  • 网络编程复习
  • 从0开始,来看看怎么去linux排查Java程序故障
  • Day31-【AI思考】-深度学习方法论全解析——科学提升学习效率的终极指南
  • Synology 群辉NAS安装(7)lsof指令和synogear
  • 半导体SAP管理系统:数字化转型的驱动力
  • ComfyUI使用教程、开发指导、资源下载
  • 微服务配置中心 Apollo解析——Portal 关联 Namespace
  • 什么是麦克斯韦方程
  • 2025年01月31日Github流行趋势
  • 3 Spark SQL
  • 【leetcode】T541 (两点反思)
  • 新一代搜索引擎,是 ES 的15倍?
  • ARM嵌入式学习--第十一天(中断处理 , ADC)
  • 编程大模型之—Qwen2.5-Coder
  • JVM方法区
  • Array,String,Number
  • ZZNUOJ(C/C++)基础练习1021——1030(详解版)
  • 白话DeepSeek-R1论文(二)| DeepSeek-R1:AI “升级打怪”,从“自学成才”到“全面发展”!
  • 数据结构-Stack和栈
  • python学opencv|读取图像(五十二)使用cv.matchTemplate()函数实现最佳图像匹配