• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring AOP can advice protected method?

 
Ranch Foreman
Posts: 1897
12
  • Mark post as helpful
  • send pies
  • 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: 1061
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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
Ranch Foreman
Posts: 1897
12
  • Mark post as helpful
  • send pies
  • 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.
 
It's never done THAT before. Explain it to me tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic