【问题标题】:spring aspectj pointcut reusable classspring aspectj切入点可重用类
【发布时间】:2017-01-25 14:17:47
【问题描述】:

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-common-pointcuts中所述

是否可以创建一个定义所有切入点的独立类并在其他方面使用它,以便我们应该能够重用切入点?

如果我使用该类的切入点,我会收到错误:

Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut inServiceLayer
    at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)

但如果我在现有方面包含该方法,它就可以正常工作。

谢谢,

【问题讨论】:

    标签: spring aspectj spring-aop pointcut


    【解决方案1】:

    这就是示例所显示的内容。

    SystemArchitecture 类定义了许多切入点,而其他类 BeforeExample、AfterReturningExample 等定义了建议,在其注释中引用了 SystemArchitecture 切入点。

    所有这些类都使用@Aspect 进行注释。

    【讨论】:

    • 这样不行,我已经附加了我的问题。
    【解决方案2】:

    都是我的错,我没有定义完全限定的方法名,包括包和类名。

    【讨论】:

    • 这就是提问时分享信息不足的问题:您必须自己找到解决方案,因为没有其他人可以帮助您。所以下次请分享SSCCE,以便问题可重现。只有没有源代码和配置的堆栈跟踪与其他方式一样无用。 ;-) P.S.:您可以接受自己的答案以关闭问题,它仍然列为未解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多