File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Aspect Oriented Programming and the fly likes Doubt regarding Spring AOP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Aspect Oriented Programming
Bookmark "Doubt regarding Spring AOP " Watch "Doubt regarding Spring AOP " New topic

Doubt regarding Spring AOP

Sumeet H Singh

Joined: Jan 03, 2009
Posts: 29
Hi all,
Had a doubt regarding the spring AOP or rather AOP in general.
If I have a class having 2 methods - MethodA() and MethodB().
Before advice is applied to MethodA() so that another method(lets say MethodC()) is called before it. This works fine if you instantiate the class through ApplicationContext and call MethodA() on that instance.

Would that method be called if we call methodA() from MethodB() directly(as in, a java method call), considering that MethodB() is called on an instance instantiated through Spring's ApplicationContext??

Its not getting called..

Please clarify whether its correct as per AOP's rules or not.

Kalyana Chakravarthy Gade

Joined: Jan 10, 2008
Posts: 1
It will not get called because Spring AOP is proxy-based. Please see this Spring documentation link for more details.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Moving to the AOP forum.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

See this thread.

At the bottom I explain how you can configure Maven to use compile time weaving to allow for self calls without the need of the proxy.

[How To Ask Questions][Read before you PM me]
Sumeet H Singh

Joined: Jan 03, 2009
Posts: 29
Thanks Kalyana and Bill!

I now have a doubt in the transaction management related to this.
The transaction propagation rules are used for specifying how a method would behave if it is called from another method which is/is not running within a transaction.

Referring to the attachment, I want to implement a scenario where method-A() has "REQUIRED" propagation level and it calls method-B(), which has "NEVER" propagation level, so that it throws an exception.

How to make sure that the transaction advice defined for method-B() (which is specified through AOP code written below) gets executed if it gets called through method-A() as displayed in the figure?


[Propagation Rules.png]

I agree. Here's the link:
subject: Doubt regarding Spring AOP
It's not a secret anymore!