This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Spring AOP can advice protected method?

 
Ranch Hand
Posts: 1769
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: 1043
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: 1769
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.
 
no wonder he is so sad, he hasn't seen this 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!