@AspectJ pointcut for all methods inside package

前端 未结 3 1814
悲&欢浪女
悲&欢浪女 2021-02-01 15:45

I have this working code for a specific package, but i want to configure it for all controllers, service and dao packages Eg

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-01 16:22

    How about one of these alternatives?

    A) General execution pointcut with package restrictions:

    execution(* *(..)) &&
    (
        within(com.abc.xyz..controller..*) ||
        within(com.abc.xyz..service..*) ||
        within(com.abc.xyz..dao..*)
    )
    

    B) Package-restricted execution pointcuts:

    execution(* com.abc.xyz..controller..*(..)) ||
    execution(* com.abc.xyz..service..*(..)) ||
    execution(* com.abc.xyz..dao..*(..))
    

    I prefer B, by the way, just because it is a bit shorter and easier to read. As you have probably guessed, the .. notation means "any package or subpackage", whereas * at the end of the expression after .. means "any method in any class".

提交回复
热议问题