This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Aop" Watch "Spring Aop" New topic
Author

Spring Aop

pankaj semwal
Ranch Hand

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

For this i did like this.

application.xml


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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Aop