This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with R: Expert techniques for predictive modeling and have Brett Lantz on-line!
See this thread for details.
Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Spring AOP can advice protected method?

 
Ranch Hand
Posts: 1758
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: 1042
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 Hand
Posts: 1758
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.
 
Danger, 10,000 volts, very electic .... tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!