美文网首页
SpringBoot Aop注解方式无法获取实现方法

SpringBoot Aop注解方式无法获取实现方法

作者: 作草分茶 | 来源:发表于2018-06-21 14:47 被阅读0次

    项目中使用自定义注解@SolrHandle写在service的实现类上,使用以下代码无法获取此注解,获取到的SolrHandle为null。

    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    SolrHandle solrHandle = method.getAnnotation(SolrHandle.class);
    

    正确方式如下

    //获取抽象方法
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    //获取当前类的对象
    Class<?> clazz = joinPoint.getTarget().getClass();
    //获取当前类有 SolrHandle 注解的方法
    method = clazz.getMethod(method.getName(), method.getParameterTypes());
    SolrHandle solrHandle = method.getAnnotation(SolrHandle.class);
    

    相关文章

      网友评论

          本文标题:SpringBoot Aop注解方式无法获取实现方法

          本文链接:https://www.haomeiwen.com/subject/vunqyftx.html