資源描述:
《spring aop中文教程(run, run, run, run aop中文教程)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、springaop中文教程(run,run,run,runaop中文教程)SpringAOPChinesetutorialThisisatutorialonSpringAOPprogrammingfoundontheInternet.Afterreadingthisarticle,SpringAOPisnolongerdifficulttounderstand,soItranslateitintoChineseandrecommendittobeginnersofSpringAOP.Thisisthelinktothetranslation.AOPisbeco
2、mingthenextHolyGrailofsoftwaredevelopment.WithAOP,youcaninjecttheaspectcodeintothemainprogram,andthemainpurposeofthemainprogramisnottodealwiththeseaspect.AOPpreventscodeclutter.TounderstandhowAOPdoesthis,thinkaboutjournaling.Thelogitselfisunlikelytobethemaintaskofthemainprogramyou'r
3、edeveloping.Itwouldbeniceifyoucouldinjectinvisible,commonlogcodeintothemainprogram.AOPcanhelpyoudoit.SpringframeworkisapromisingAOPtechnology.Asanoninvasive,lightweightAOPframework,youcanuseitinaJavaprogramwithoutusingprecompiledorothermetatags.Thismeansthatonlyonepersoninthedevelop
4、mentteamhastodealwithAOPframework,andtheothersareprogrammingasusual.AOPisthesourceofmanyhardtounderstandterms.Fortunately,aslongasyouunderstandthreeconcepts,youcanwritetheAOPmodule.Thethreeconceptsare:advice,pointcut,andadvisor.Adviceisthecodethatyouwanttoinjectintodifferentplacesin
5、sideanotherprogram.Pointcutdefinesalocationwhereadviceneedstobeinjected,usuallyapublicmethodforaparticularclass.Advisoristheassemblerofpointcutandadvice,whichisthecodethatinjectadviceintopredefinedpositioninmainprogram.Nowthatweknowthatweneedtouseadvisortoinjectinvisibleadviceintoth
6、emaincode,let'simplementanexampleofSpringAOP.Inthisexample,we'llimplementabeforeadvice,whichmeansthattheadvicecodeisexecutedbeforetheinvokedpublicmethodstarts.Hereistheimplementationcodeforthisbeforeadvice:Code:Packagecom.company.springaop.test;Importjava.lang.reflect.Method;Importo
7、rg.springframework.aop.MethodBeforeAdvice;PublicclassTestBeforeAdviceimplementsMethodBeforeAdvice{Publicvoidbefore(Methodm,Object[]args,Objecttarget)ThrowsThrowable{System.out.println("Helloworld!!"(by)"+this.getClass().GetName()+""";}}InterfaceMethodBeforeAdvicehasonlyonemethod,bef
8、oreneedstobeimpleme