小编var*_*raJ的帖子

调用Around方面时的AOP异常

我试图在所有服务方法上运行一个方面.但对于具有原始返回类型的方法,这似乎失败了.我收到此错误org.springframework.aop.AopInvocationException:来自通知的空返回值与原始返回类型不匹配.是否有必要用于方面的所有方法都需要具有非原始返回类型?谢谢

  @Aspect
@Component
public class ServiceAspect
{
    private static final Logger LOG = Logger.getLogger(ServiceAspect.class);

   @Pointcut("execution(* com.xxx.service..*.*(..))")

    public void perform()
    {

    }

    @Around("perform()")
    public void performTimeCal(ProceedingJoinPoint joinPoint)
    {
        try
        {
            Date start = DateUtils.newDate();
            String processingTime = null;
            joinPoint.proceed();

            processingTime = DateUtils.computeDateDifference(start,
            DateUtils.newDate());
            LOG.info("STAT: " + getSimpleClassName(joinPoint) + "."
            + joinPoint.getTarget() + "(): " + processingTime);
        }
        catch (Throwable e)
        {
            e.printStackTrace();
        }

    }

    private String getSimpleClassName(ProceedingJoinPoint joinPoint)
    {
        if (joinPoint.getThis() != null)
        {
            return joinPoint.getThis().getClass().getSimpleName();
        }
        return "";

    }

} …
Run Code Online (Sandbox Code Playgroud)

aop spring

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

aop ×1

spring ×1