Java 不同包中特定方法的切入点表达式

Java 不同包中特定方法的切入点表达式,java,aop,aspectj,spring-aop,Java,Aop,Aspectj,Spring Aop,我在@Around建议中尝试了一个特定包的切入点表达式,如com.abc.def.controller,com.abc.def.service.serviceImpl等,如下所示: @Around("execution(* com.abc.def.controller..*.*(..))") @Around("execution(* com.abc.def.service.*Impl.*(..))") 我还需要匹配不同软件包中的方法,如com.abc.xyz.controller,com.ab

我在
@Around
建议中尝试了一个特定包的切入点表达式,如
com.abc.def.controller
com.abc.def.service.serviceImpl
等,如下所示:

@Around("execution(* com.abc.def.controller..*.*(..))")
@Around("execution(* com.abc.def.service.*Impl.*(..))")
我还需要匹配不同软件包中的方法,如
com.abc.xyz.controller
com.abc.xyz.service.serviceImpl
,并尝试了许多切入点表达式,但都不起作用


任何帮助都将不胜感激。:)

请尝试下面的表达式

@围绕(“执行(*com.abc.def.controller.*.(..)”)

这个怎么样

@Around(“执行(*com.abc..controller..*(..)”)
@大约(“执行(*com.abc..service.*Impl.*(..)”)
您还可以同时匹配这两个选项,如下所示:

周围( “执行(*com.abc..controller.*(..)| |”+ “执行(*com.abc..service.*Impl.*(..)” )
其他变体也是可能的,具体取决于您想要实现的目标。请随时提出相关的后续问题。

它只匹配com.abc.def包中的方法。我需要com.abc.def和com.abc.xyz。我试着概括一下,我没有试过,但是你可以@Around(“in(com.abc..*)”)谢谢你的回答。我有一个问题,我刚刚在控制器表达式中添加了一些语句,如@Around(“execution(*com.abc..controller..*(..)&&&&@annotation(CustomAnnotation)”。它不起作用。我是否遗漏了一些代码或所需的确认?在基于AspectJ注释的语法中,需要使用完全限定的类名,如
com.abc.blah.CustomAnnotation
。在本机AspectJ语法中,这是不必要的。。。导入java.lang.annotation.ElementType;导入java.lang.annotation.Retention;导入java.lang.annotation.RetentionPolicy;导入java.lang.annotation.Target@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE,ElementType.METHOD})public@interface CustomAnnotation{String methodName();String TYPE();}需要其他配置吗?包名!!!请在切入点中使用完全限定的类名,包括包名,就像前面注释中的示例一样。同样:
@Around(“execution(*com.abc..controller..*(..)&&&&@annotation(my.package.name.MyAnnotation)”)