• 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 can advice protected method?

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, in Getting Started with Spring Framework 5  4th edition , it says Spring AOP  only advices public joint point.
But as I tried , Spring AOP can advice protected or package friendly joint point like this:

@Before("execution(protected *  com..*(..))")
public void callBefore(){...}


Can anyone confirm me that Spring AOP can advice any joint point with any visibility except private?
 
Bartender
Posts: 1155
20
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it says Spring AOP  only advices public joint point

- I would suspect that will be correct, if its a quote from a book written by one of the actual spring framework developers.

The reason behind this may be (note the language - I'm not 100% sure of this) due to the way in which spring uses dynamic run time proxies to implement AOP features.  Would a proxy object then have the visibility to a class defined with protected (or default) access, I assume that it would not.  Here's the relevant section from the  Spring AOP documentation.  

My advise would be to look into AspectJ.    

 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Peter,
If the Dynamic JDK proxy is used, only public method can be proxied since we can only define public method in an interface.
And protected methods of the target object (the bean) cannot be called as this bean is called through its interface.

But if CGLib proxy is used, public and protected methods can be proxied.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic