Java joinPoint.procedure()做什么?

Java joinPoint.procedure()做什么?,java,spring-boot,aop,aspectj,Java,Spring Boot,Aop,Aspectj,这是我第一次接近AOP。我有一个spring boot应用程序,其中一个方面是记录器。通过搜索,我得出的结论是@Around方法在方法之前和之后执行(我只是在一个方法中调用它),对吗? 在我的@环绕方法y的中间有一个连接点。如果我没有错的话,JoinPoint是我必须用来获取调用方面的方法信息的对象,但我不知道进程实际上在做什么 这是我的代码: @Around(value = "execution(* *(..)) && @annotation(Loggable)", argNa

这是我第一次接近AOP。我有一个spring boot应用程序,其中一个方面是记录器。通过搜索,我得出的结论是@Around方法在方法之前和之后执行(我只是在一个方法中调用它),对吗? 在我的@环绕方法y的中间有一个<代码>连接点。如果我没有错的话,
JoinPoint
是我必须用来获取调用方面的方法信息的对象,但我不知道进程实际上在做什么

这是我的代码:

@Around(value = "execution(* *(..)) && @annotation(Loggable)", argNames = "ProceedingJoinPoint, Loggable")
public Object logAround(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {

    String methodArguments = loggable.printMethodArguments() ? Arrays.toString(joinPoint.getArgs()) : "[]";

    long start = System.currentTimeMillis();
    Object returnObject = joinPoint.proceed(); // continue on the
                                                // intercepted method
    long elapsedTime = System.currentTimeMillis() - start;

    String returnValue = loggable.printReturn() && returnObject != null ? returnObject.toString() : "[]";

    LOG.info("Logging method: {}.{} Method arguments: {}. Method return value: {}. Method execution time: {}",
            joinPoint.getTarget().getClass().getName(), joinPoint.getSignature().getName(), methodArguments,
            returnValue, elapsedTime);
    return returnObject;
}

正如您所提到的,
@Around
建议围绕一个连接点,例如方法调用。它可以在方法调用前后执行自定义行为。它还负责选择是继续执行连接点还是缩短建议方法的执行


在您的例子中,实际的方法调用(那些包含非常有用的业务逻辑的方法!)是因为
joinPoint.procedure()

正如您所说,当您使用
@Around
时,就像您可以在方法之前执行任何您想执行的操作,然后调用方法,然后在调用方法之后执行任何您想执行的操作一样

//Read file, Log , .... (Before method calling)
//Invoke the method (joinPoint.proceed)
//Write to the file, complete log, .... (After method calling)
调用阶段由
joinPoint.procedue()
完成


日志示例 1-调用方法前记录日志

2-调用或调用在其上设置切入点的方法(
继续

3-将日志保存到数据库中,或将其写入文件,或将其发送

授权示例 在本示例中,使用
@Around
,您可以授权用户并确定他们是否可以使用该方法

因此,您需要在方法调用之前执行授权过程,如果授权为
true
,则调用方法,如果不抛出异常或您可以记录

1-在调用方法之前授权用户

2-如果授权为
true
,则调用方法(
joinPoint.procedue();



总结
连接点。继续()
表示您正在调用set方法或调用它。

具体的混淆是什么?API和注释都精确地描述了它的功能。哦,谢谢!你的回答很清楚。那么,如果我在和<代码>之前使用<代码> @,在注释中,在中间使用“连接点”/<代码>与“连接点”/[代码]相同,在中间,这种替换不适合您的示例,因为您正在测量经过的时间。这不是
@之前
@之后
的最佳用例。