Spring Strategy Study Notes (3.03) -- Access Connection Point Information

Source: Internet
Author: User

I. knowledge points

In AOP, notifications apply to differentProgramExecution point. These execution points are called connection points.. In order for the notification token to take the correct action, the detailed information of the connection point is often required.The notification can declare an org. aspect. Lang. joinpoint parameter in the notification method signature to access the current connection point information..

II,CodeExample

You can use the following notifications to access the connection point information. This information includesConnection point type (only method-execution in Spring AOP)Method signature (Declaration type and method name) and parameter value, as well as target object and proxy object.

/** Copyright 2013-2015 */package COM. codeproject. jackie. springrecipesnote. springaop; import Java. util. arrays; import Org. apache. commons. logging. log; import Org. apache. commons. logging. logfactory; import Org. aspectj. lang. joinpoint; import Org. aspectj. lang. annotation. aspect; import Org. aspectj. lang. annotation. before;/*** title: caculatorloggingaspect. java ** @ author Jackie * @ since May 3, 2013 9:11:49 * @ version V1.0 */@ aspectpublic class caculatorloggingaspect {private log = logfactory. getlog (this. getclass (); @ before ("execution (**. *(..)) ") Public void logbefore (joinpoint) {// connection point type log.info (" joint point kind: "+ joinpoint. getkind (); // method signature declaration type log.info ("signature declaring type:" + joinpoint. getsignature (). getdeclaringtypename (); // method Signature Name log.info ("Signature Name:" + joinpoint. getsignature (). getname (); // parameter log.info ("arguments:" + arrays. tostring (joinpoint. getargs (); // the target object log.info ("target class:" + joinpoint. gettarget (). getclass (). getname (); // proxy object log.info ("this class:" + joinpoint. getthis (). getclass (). getname ());}}

the original bean encapsulated by the proxy is called the target object, and the proxy object is called the this object. These two objects can be accessed by the gettarget () and getthis () Methods of the connection point . From the following output, you can see that the classes of these two objects are different:

May 07,201 3 10:48:52 Org. springframework. beans. factory. XML. xmlbeandefinitionreader loadbeandefinitionsinfo: loading XML bean definitions from class path resource [applicationcontext. XML] May 07,201 3 10:48:53 Org. springframework. beans. factory. support. defaultlistablebeanfactory preinstantiatesingletonsinfo: Pre-instantiating singletons in org. springframework. beans. factory. support. defaultlistablebeanfactory @ 6261c9: defining beans [Org. springframework. AOP. config. internalautoproxycreator, arithmeticcalculator, unitcalculator, Com. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect #0]; root of factory hierarchymay 07,201 3 10:48:54 COM. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect logbeforeinfo: joint point kind: method-executionmay 07,201 3 10:48:54 COM. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect logbeforeinfo: Signature declaring type: COM. codeproject. jackie. springrecipesnote. springaop. arithmeticcalculatormay 07,201 3 10:48:54 COM. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect logbeforeinfo: Signature Name: addmay 07,201 3 10:48:54 COM. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect logbeforeinfo: arguments: [1.0, 2.0] May 07,201 3 10:48:54 COM. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect logbeforeinfo: Target class: COM. codeproject. jackie. springrecipesnote. springaop. arithmeticcalculatorlmplmay 07,201 3 10:48:54 COM. codeproject. jackie. springrecipesnote. springaop. caculatorloggingaspect logbeforeinfo: this class: COM. sun. proxy. $ proxy61.0 + 2.0 = 3.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.