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

查看:112
本文介绍了从特定类中调用某些方法时执行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?

例如,我有类"A"具有方法getA.我已经成功实现了执行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 B 中的 Class A 的对象.这是因为,AOP是使用代理通过Spring实现的,因此,注入的实例将是包装定义了方面的类的对象的代理.因此,只要您在Spring托管的bean上调用 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天全站免登陆