Spring AOP pointcut that matches annotation on interface

后端 未结 2 646
梦谈多话
梦谈多话 2020-12-01 06:14

I have a service class implemented in Java 6 / Spring 3 that needs an annotation to restrict access by role.

I have defined an annotation called RequiredPermission t

相关标签:
2条回答
  • 2020-12-01 07:00

    Espen, your code works only for one class:

    execution(public * com.mycompany.myservice.MyService+.*(..))
    

    but what if I want this behaviour for all services in *com.mycompany.services.** package?

    0 讨论(0)
  • 2020-12-01 07:13

    If I understand you correct, you want a pointcut that finds all methods in classes that extends MyService and is annotated and with the preferred arguments.

    I propose that you replace:

    execution(public * com.mycompany.myserviceimpl.*(..))
    

    with:

    execution(public * com.mycompany.myservice.MyService+.*(..))
    

    The plus sign is used if you want a joinpoint to match the MyService class or a class that extends it.

    I hope it helps!

    0 讨论(0)
提交回复
热议问题