从特定类调用某些方法时执行 AOP [英] Executing AOP when some method is called from specific class

查看:30
本文介绍了从特定类调用某些方法时执行 AOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 AOP 的新手.当执行某个类的某些方法时,我可以成功执行 AOP.但是当某个类的某些方法从其他类调用时,我想执行 AOP.这种类型的实现可以在 SpringAOP 或 AspectJ 中实现吗?

I am new to AOP. I can successfully execute the AOP when some method of some class is executed.But i want to execute the AOP when some method of some class is called from other class. Is this type of implementation is possible in SpringAOP or AspectJ?

例如,我有具有方法 getA 的A"类.我已经成功地实现了,当 getA 被执行时,做一些事情".但我想要当从B"类调用 getA 时,做一些事情".是否可以在 Spring AOP 或 AspectJ 中使用?

For Example,I have Class "A" having method getA. I have successfully implemented, "when getA is executed, do something". But i want " When getA is called from class "B", do something". Is it possible in Spring AOP or AspectJ?

推荐答案

当从B"类调用 getA 时,做某事.在 Spring AOP 或 AspectJ 中可以吗?

When getA is called from class "B", do something". Is it possible in Spring AOP or AspectJ?

可以,前提是Class BClass A的对象被注入.这是因为,AOP 是由 spring 使用代理实现的,因此注入的实例将是包装定义切面的类的对象的代理.所以,只要你在 spring-managed beans 上调用 getA() 方法,连接点就会被执行.

Yes, provided the object of Class A in Class B is injected. This is because, AOP is implemented by spring using proxies and hence the injected instances will be proxies wrapping the object of the class on which aspects are defined. So, as long as you call getA() method on spring-managed beans, the join points get executed.

这篇关于从特定类调用某些方法时执行 AOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆