AspectJ的 - 为切入点,除了一个包中的所有类

问题描述 投票:0回答:2

我目前使用的对通话记录在我的应用程序的每个服务方法的方法,下面的切入点:

@Before("execution(* com.mdenis.someAppName..service..*(..))")

有问题的方法使用Apache的记录仪和完美的作品。我现在想这些日志记录语句写入到数据库,以及(通过LogEntryService类)。问题是,这基本上是因为,在该服务包日志一切都调用同一封装内的方法,该方法创建一个StackOverflow的错误。

有没有办法改变我的切入点,以排除某一类?

java class spring-boot package aspectj
2个回答
0
投票

这个怎么样?

@Before(
  "execution(* com.mdenis.someAppName..service..*(..)) && " + 
  "!within(*..LogEntryService)"
)

0
投票

我结束了一个类的切入点与注释切入点像这样的组合:

@Pointcut("execution(* com.service.processes.communication.CommunicationProcess.*(..))")
private void communicationMethods() {}

@Pointcut("execution(@com.lib.annotation.Loggable * *.*(..))")
private void loggableMethods() {}

@Before("communicationMethods() && loggableMethods()")
public void logMethodCallWithParameters(JoinPoint joinPoint)
{
    if (joinPoint.getArgs().length == 0)
    {
        logEntryService.logDebug(LogEntrySource.SERVICE, LogEntryType.MESSAGING, "Method " + joinPoint.getTarget().getClass().getCanonicalName() 
            + "." + joinPoint.getSignature().getName() + " called with no argument", logger);
    }
    else
    {
        logEntryService.logDebug(LogEntrySource.SERVICE, LogEntryType.MESSAGING, "Method " + joinPoint.getTarget().getClass().getCanonicalName() 
            + "." + joinPoint.getSignature().getName() + " called with argument(s) " + getArgumentString(joinPoint.getArgs()), logger);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.