将 AOP xml 配置转换为 Java

Converting AOP xml config to Java

我有以下基于 xml 的 AOP 代码

    <aop:config>
        <aop:pointcut id="handlerMethodAop"
            expression="execution(@org.springframework.web.bind.annotation.RequestMapping * *(..))" />

        <aop:advisor pointcut-ref="handlerMethodAop"
            advice-ref="handlerMethodAdvice" />
        <aop:advisor pointcut-ref="handlerMethodAop"
            advice-ref="handlerMethodThrowsAdvice" />
        <aop:advisor pointcut-ref="handlerMethodAop"
            advice-ref="warningThrowsAdvice" />
    </aop:config>

advice-ref 属性中的值是我在别处声明的 bean。

如何将其转换为 Java 配置?我的应用程序的 90% 已经在使用 Java 配置,因此我不需要有关如何执行此操作的基础知识的课程,特别是如何配置此 AOP 内容。

  1. @Aspect 组件中使用建议声明而不是顾问。
  2. 使用声明性 @Configuration 元素,例如 @EnableAspectJAutoProxy 而不是 XML 配置。

Spring AOP manual