If there is such a scenario, how long does it take to count the time a method executes ?
The typical idea is to record the time before the method executes, and then record it again after the method executes, to get the run time.
With spring AOP, it is impossible to use only the pre-and post-methods, because they cannot share variables. This can be achieved quickly by wrapping notifications.
The wrapping notification class is declared first in the Slice notification class:
Public voidwatchperformance (Proceedingjoinpoint joinpoint) {Try{System. out. println ("begin!"); LongStart =System.currenttimemillis (); Joinpoint.proceed (); LongEnd =System.currenttimemillis (); System. out. println ("end! Performance took"+ (End-start) +"milliseconds"); }Catch(Throwable e) {System. out. println ("eee! We want Our money back!"); } }
To configure Aop:around in the Bean.xml configuration file, lock the method:
<pointcut-ref= "Performance" method= "Watchperformance" />
The results of this implementation are as follows:
The audience is taking their seats. The audience is turning off their cellphonesbegin! Instrumentalist age:25playing jingle Bells:toot toot Tootclap clap clapend! Performance took milliseconds
So you can see that the process of AOP execution is as follows:
Before () Around () execution method () After/throw () Around ()
"Spring Combat"--9 AOP Surround Notification