Sunil luitel
Sunil luitel

Reputation: 980

Executing AOP when some method is called from specific class

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?

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?

Upvotes: 1

Views: 426

Answers (1)

Vikdor
Vikdor

Reputation: 24134

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

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.

Upvotes: 1

Related Questions