开发者社区 问答 正文

Spring AOP中在切点中如何引用Bean?

已解决

Spring AOP中在切点中如何引用Bean?

展开
收起
去校区学技术 2022-04-01 06:59:48 835 分享 版权
2 条回答
写回答
取消 提交回答
  • 推荐回答

    Spring还提供了一个bean()描述符,用于在切点表达式中引用Spring Beans。例如:

    excecution(* com.tianmaying.service.BlogService.updateBlog(..))  and bean('tianmayingBlog')
    

    这表示将切面应用于BlogService的updateBlog方法上,但是仅限于ID为tianmayingBlog的Bean。

    也可以排除特定的Bean:

    excecution(* com.tianmaying.service.BlogService.updateBlog(..))  and !bean('tianmayingBlog')
    
    2022-04-01 07:00:54
    赞同 展开评论
  • 使用切点表达式

    2022-12-29 15:53:34
    赞同 展开评论