使用SpringAOP的Java方法内省

使用SpringAOP的Java方法内省,spring,reflection,spring-aop,Spring,Reflection,Spring Aop,我使用SpringAOP对我的服务方法进行了一些处理。必须进行治疗的方法用@History注释。此外,注释可以有一些参数,如“comment”。以下是示例: @Service public class MyServiceImpl implements IMyService { @Override @History(comment = "my comment") public void myMethod() {...} } public interface IMyServ

我使用SpringAOP对我的服务方法进行了一些处理。必须进行治疗的方法用@History注释。此外,注释可以有一些参数,如“comment”。以下是示例:

@Service
public class MyServiceImpl implements IMyService {
    @Override
    @History(comment = "my comment")
    public void myMethod() {...}
}

public interface IMyService {
    void create();
}
我有一个方面的定义如下:

@Aspect
@Component
public class MyHistoryAspect {

    @AfterReturning(pointcut = "execution(* my.service.package.*(..)) && @annotation(history)", returning = "result")
    public void myTreatment(JoinPoint joinPoint, History history, Object result) {

        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Method method = methodSignature.getMethod();

        ...
    }
}
现在,我的问题是:当我使用反射来找出“评论”在我的方面的价值时,我找不到它。原因:该方法是IMyService的方法签名,而不是MyServiceImpl的方法签名。如果我把注释放在接口上而不是服务上,我的方面就永远不会到达

我是遗漏了什么还是spring aop的正常行为


谢谢

您能给我们看一下您的反射检查吗?当我执行method.getAnnotations()时,它返回一个空值。您能在运行时检查类的类型吗?或者选择instanceof to您的Impl objI不能直接拥有对象。我可以使用joinPoint.getTarget(),类是MyServiceImpl。你能给我们看一下你的反射检查吗?当我使用method.getAnnotations()时,它返回一个空值。你能在运行时检查类的类型吗?或者选择instanceof to您的Impl objI不能直接拥有对象。我可以使用joinPoint.getTarget(),类是MyServiceImpl。