【问题标题】:spring aop expression for subpackages子包的spring aop表达式
【发布时间】:2012-05-15 06:33:51
【问题描述】:

我已经围绕类型编写了 spring aop 表达式,例如

@Around("execution(* com.mycomp.proj.parent.child1.*.*(..))
|| execution(* com.mycomp.proj.parent.child2.*.*(..))")

但如果新包将在父级(e.g.:com.mycomp.proj.parent.child3 下创建,则此表达式不会应用于新包)。如何开发包含这一点且不适用于直接位于父包中的类的表达式? (仅适用于所有子包中的类的表达式)

【问题讨论】:

    标签: java spring aop spring-aop


    【解决方案1】:

    排除父级:

    @Around("execution(* com.mycomp.proj.parent.*.*(..))
    && ! execution(* com.mycomp.proj.parent.*(..))")
    

    【讨论】:

    • 它不起作用。因此,它在尝试设置上下文时抛出异常:“引起:java.lang.IllegalArgumentException:警告此类型名称不匹配:com.mycomp.proj.parent [Xlint:invalidAbsoluteTypeName]”
    【解决方案2】:

    @Around("执行(* com.mycomp.proj.parent.child1..(..)) ||执行(* com.mycomp.proj.parent.child2..(..))")

    【讨论】:

      【解决方案3】:

      如下申请一个额外的时间

      @Around("execution(* com.mycomp.proj.parent..*.*(..))")
      

      它将允许对 com.mycomp.proj.parent 的所有子包进行切入点

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多