gpt4 book ai didi

java - 将 AOP xml 配置转换为 Java

转载 作者:行者123 更新时间:2023-11-30 07:02:25 25 4
gpt4 key购买 nike

我有以下基于 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 Config?我的应用程序 90% 已经在使用 Java 配置,因此我不需要有关如何执行此操作的基础知识的类(class),特别是如何配置此 AOP 内容。

最佳答案

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

参见Spring AOP manual .

关于java - 将 AOP xml 配置转换为 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40685301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com