File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes 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 » Spring
Bookmark "Spring Aop" Watch "Spring Aop" New topic

Spring Aop

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 303
I want when a accesUser method call the afterLogged method should be called.

For this i did like this.


And calling like this

And Action class is

Where secure method is a interface and have two method authencate and accesUser.And secureAdvice is a advice.

The above scenerio works fine but when i call accessUser in side authencate its not works.
Afte that i called like this

Please tell me how to solve this.

Thank & Regards

Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

This is a known limitation of Spring AOP while using proxies. If you are calling method in same class it will not be intercepted. i:e you have class Foo with public methods a() & b(). If these methods are called from another class, the call will be intercepted, however if you call method b() from a(), Spring AOP will not intercept it.
A possible workaround is that you can try using CGLIB for weaving.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

For me, this type of scenario shows me a "Code smell". It says to me to look at my design and refactor it.

While you can add the CGLIB jar file to get proxies created by subclassing your class, it is a "workaround" for a bad design in your apis.

If you truly have one public method of a class/interface calling another public method of the same class/interface then you are making your class a client of itself. a client means a class outside of that class calling it.

So if I have this scenario, my refactor is either to move one of the methods into another class/interface, or make one of the two methods private. If the two methods hae to be public because they both are called outside of the class by other classes, then my first refactor is what should be done.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Spring Aop
It's not a secret anymore!