• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Aop

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic