• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Aop

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic