三大框架spring3.0上課提綱_第1頁(yè)
三大框架spring3.0上課提綱_第2頁(yè)
三大框架spring3.0上課提綱_第3頁(yè)
三大框架spring3.0上課提綱_第4頁(yè)
三大框架spring3.0上課提綱_第5頁(yè)
已閱讀5頁(yè),還剩27頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Spring3.0框框架需求分問(wèn)題描述:編碼依賴問(wèn)publicclassStudentActionpublicclassStudentAction privateStudentServicestudentService=privateStudentpublicStudentgetStudent()return}publicvoidsetStudent(Studentstudent)this.student=}publicStringsave(){return"success";}}同樣在業(yè)務(wù)邏輯層調(diào)用數(shù)據(jù)層中,也會(huì)出現(xiàn)如下問(wèn)題publicpublicclassStudentServiceimplimplementsStudentService 層也要切換,但是目前new之后不方便修privateStudentDaostudentDao=newpublicvoidsave(Studentstudent){}}以上代碼是有問(wèn)題的,即在控制層中依賴了具體的業(yè)務(wù)邏輯層在業(yè)務(wù)邏輯層中依賴了具體的數(shù)據(jù)層.這樣就和具體的實(shí)現(xiàn)類耦合在了一起也沒(méi)有發(fā)揮面向接口編程的作用.如果要更換(比如要換成StudentDaoOracleImpl需要修改源代碼,但是項(xiàng)目很多模塊都需要同時(shí)修改,這樣會(huì)非常麻煩.class文件,覆蓋原來(lái)的文件.不利于項(xiàng)目的后期,而且項(xiàng)目與項(xiàng)目之間的依賴隱藏在了代碼中.也不適合全局把握正個(gè)項(xiàng)目,因此性和二次開(kāi)發(fā)比較麻煩解決方案1:工廠模可以使用抽象工廠,StudentDaoStudentService的實(shí)現(xiàn)在在工廠中生成,而工廠可以根據(jù)配置文件的指定類型,來(lái)創(chuàng)建不同的對(duì)象,而且工廠本身一般是不變的.從而降低了對(duì)可以變的業(yè)務(wù)邏輯類的依賴,接近的軟件的設(shè)計(jì)目標(biāo)”高內(nèi)聚,低耦合”publicclassStudentActionpublicclassStudentAction依賴具體的對(duì)象,改為依賴工廠而工廠創(chuàng)建的路徑來(lái)自具體的配置文件,所以靈活必須 privateStudentServiceprivateStudentpublicStudentgetStudent()return}publicvoidsetStudent(Studentstudent)this.student=}publicStringsave(){return"success";}}業(yè)務(wù)邏輯層→抽象工廠→數(shù)據(jù)publicpublicclassStudentServiceImplimplementsStudentServiceprivateStudentDaopublicvoidsave(Studentstudent){}}個(gè)實(shí)現(xiàn)類,只需要修改配置文件就可以了,注意這里只是降低了層與層之間的復(fù)雜度,并沒(méi)有讓耦合,實(shí)際上層與層是不可能沒(méi)有耦合的,我們學(xué)框架的目的就是要找到變的部分,OK了,不需要修改代碼本身建的時(shí)候有些類需要初始化操作,有些又不需要初始化數(shù)據(jù)…..這又怎么辦呢?那就要再完善一下這個(gè)工廠類了,或者多創(chuàng)建一些工廠了.讓工廠可以處理這些問(wèn)題,但是我們自己實(shí)解決方2:IOC依賴注所謂依賴注入就是指在運(yùn)行期,由外部配置文件動(dòng)態(tài)地將本身所依賴對(duì)象通過(guò)set方法注入到組件中,我們只需要用即可,而不需要在去管理對(duì)象的創(chuàng)建和銷毀我們期望的代publicpublicclassStudentAction//privateStudentServicepublicvoidsetStudentService(StudentServicestudentService)this.studentService=}privateStudentpublicStudentgetStudent()return}publicvoidsetStudent(Studentstudent)this.student=}publicStringsave(){return"success";}}publicpublicclassStudentServiceImplimplementsStudentService//privateStudentDaopublicvoidsave(Studentstudent){}}問(wèn)題描述:編程式事publicpublicvoidsave(StudentSession//手動(dòng)控制的事務(wù)稱為編 try}}catch(HibernateExceptione){}}以上代碼是有問(wèn)題的,紅色的部分,每次只要有數(shù)據(jù)修改操作的時(shí)候則都要編寫(xiě),要的是這些代碼與方法的功能本身又沒(méi)有緊密的聯(lián)系.而且基本每個(gè)模塊都有,重復(fù)的代碼大大降低了我們的效率和增加了的成本,解決方案1:模類,來(lái)完成Session事務(wù)的提交、回publicclass implementsSessionprivateSessionsession=null;publicSession (Sessionsession){this.session=}publicvoidbegin(){}publicvoidrollback(){}publicvoidsave(Studentstudent)try}catch(Exceptione)}finally}}publicvoidcommit(){}}:publicpublicvoidsave(StudentHibernateSessionFactory返回的是session的 //的save中調(diào)用了begincommit或者} .而且 但是我們的事務(wù)基本所有的業(yè)務(wù)邏輯模塊都有.}解決方案2:AOP式事Spring3.0介Spring主要功能介紹Spring的IOC容器包含并管理應(yīng)用對(duì)象的配置和生命周期,你可以配置你的每個(gè)bean如何被創(chuàng)建,也可以配置每個(gè)bean是只有一個(gè)實(shí)例,還是每次需要時(shí)都生成一SpringAOP提供了很多基礎(chǔ)但是與業(yè)務(wù)邏輯無(wú)關(guān)的功能,比如:事務(wù)管理、與持久Spring還提供了自己的MVC實(shí)現(xiàn),和 te來(lái)簡(jiǎn)化數(shù)據(jù)操Spring功能結(jié)構(gòu)Spring的好降低組件之間的耦合度,實(shí)現(xiàn)軟件各層之間的解耦容器提供了AOP技術(shù),利用它很容易實(shí)現(xiàn)如權(quán)限、運(yùn)行期等功能容器提供的眾多輔作類,使用這些類能夠加快應(yīng)用的開(kāi)發(fā),如:JdbcTem Spring對(duì)于主流的應(yīng)用框架提供了集成支持集成HibernateJPA等,實(shí)現(xiàn)框架之間的無(wú)縫集成,這樣更便于應(yīng)用的開(kāi)發(fā)SpringSpring資源地Spring框架的主頁(yè):Spring框架地址: oSpring開(kāi)發(fā)環(huán)境SpringJarSpirng3-AOPAOP功能,Spring3-CoreIOC功能,Spring3-Persistence-JDBC:SpringJDBCSpring配置文件時(shí),不能出現(xiàn)幫助信息解決方法1:讓機(jī)器上網(wǎng),eclipse會(huì)自動(dòng)從網(wǎng)絡(luò)上schema文件并緩存在硬盤上2:schema文件,方法如下:1:windows→preferences→myeclipse→filesandeditors→xmlxmlcatalog2:點(diǎn)"add",在出現(xiàn)的窗口中的KeyType中選擇URI,在location中選"Filesystem",spring解壓的dist/resourcesspring-beans-3:回到設(shè)置窗不要急著關(guān)閉窗口,應(yīng)把窗口中的KeyType改為Schemalocation,Key改為第一Spring程序(IOC解決編碼依賴"""applicationContext.xml取代了前面的properties配置文件<bean 指向另一個(gè)id此處說(shuō)明studentService依賴studentDaostudentDao屬性是私有的,必須通過(guò)set方法注入<propertyname="studentDao"ref="studentDao"配置studentDaoclass是具體的業(yè)務(wù)邏輯bean<beanid="studentDao" .ssh.b.StudentDaoImpl"publicpublicclass_IOCTestpublicvoidResourceSpringResourceresource=new 建BeanFactorybeanFactory=newgetBean通過(guò)name和id去查找實(shí)例化的對(duì)象,通過(guò)Spring容器拿出來(lái)的對(duì)Studentstudent=newStudent("test",13);}}Spring來(lái)管理Action<beanSpring來(lái)管理Action<beanid="studentAction"action在創(chuàng)建的時(shí)候會(huì)把service通過(guò)set<propertyname="studentService"ref="studentService"@Test@Test測(cè)試Spring管理Action-->Service--publicvoidtest02(){Resourceresource=newBeanFactorybeanFactory=newStudent應(yīng)該通過(guò)前臺(tái)傳入,Studentstudent=newStudent("test2",13);}}Spring的依賴注入功能,Spring的配置文件,y來(lái)獲取想要的Ben對(duì)象,代碼中只聲明了一個(gè)接口類型例如、o這樣大大提高了代碼的靈活性(消除了編譯時(shí)依賴,讓運(yùn)行時(shí)依賴具體的接口類型,而且以后可以動(dòng)態(tài)變化g給OC功能Resource幾種方classpathTomcatapplication配置文件,必@Test測(cè)試獲取Resourcepublic@Test測(cè)試獲取Resourcepublicvoidtest03()throwsException{Resourceresource=null;BeanFactorybeanFactory=null;//resource=newClassPathResource("applicationContext.xml");beanFactory=newXmlBeanFactory(resource);//通過(guò)文 beanFactory=newXmlBeanFactory(resource);}org.springframework.core.io.Resourceresource=null;BeanFactoryApplicationContext的比ApplicationContextBeanFactoryBeanFactoryBean容器,ApplicationContextApplicationContextBeanFactory,如它可以加載外部的資源文件、可以自AOP切面........classpathTomcatapplication配置文件,必@Test測(cè)試Applicationpublic@Test測(cè)試Applicationpublicvoidtest04()throwsException{ApplicationContextcontext=new}://必須放到web環(huán)境下執(zhí)行下面的語(yǔ)句SpringIOC詳解(重點(diǎn)Bean的三種方<beanid="studentDao" .ssh.c.StudentDaoImpl"<beanid="studentDao" .ssh.c.StudentDaoImpl" factory-method="getBean"publicpublicclassStudentDaoFactorypublicstaticStudentDaogetBean(){ StudentDaoImplimpl=newreturn}}factory-beanref一個(gè)普通工廠<beanid="studentDao"factory-bean="studentDaoFactory"method="getBean" .ssh.c.StudentDaoFactory"publicvoid}Bean的生命周getBean()時(shí)才生成實(shí)例)單例模式+publicvoidpublicvoidtest02(){ApplicationContextcontext=new} 單例模式+懶漢式創(chuàng)建(用的時(shí)候在創(chuàng)建)注意:<bean<beanid="studentDao"init="true".ssh.c.StudentDaoImpl" bean<beans<beansdefault-lazy-init="true"SingletionSpring容器管理的都是業(yè)務(wù)邏輯類,因?yàn)橹挥袠I(yè)務(wù)邏輯類才會(huì)經(jīng)常變化.業(yè)務(wù)邏輯類盡量避免設(shè)計(jì)全局變量,Singletion模式可能會(huì)出現(xiàn)問(wèn)題,90%的時(shí)候業(yè)務(wù)邏輯類餓漢模式即可,也就是項(xiàng)目啟動(dòng)的時(shí)候初始化Action必須是多例的,所以要配置prototype屬性,<beanid="studentAction" Action必須是多例的,所以要配置prototype屬性,<beanid="studentAction" <!--studentService是否為多例,決定studentServicescope<propertyname="studentService"ref="studentService"@Test@Test//測(cè)試actionscope="prototype"publicvoidtest03(){ApplicationContextcontext=new }Prototypescopeprototype則默認(rèn)是懶漢模式,因?yàn)槎嗬谶\(yùn)行時(shí)候創(chuàng)建是沒(méi)有意義的.Spring不負(fù)責(zé)prototype的銷毀.換句話來(lái)說(shuō),Spring把創(chuàng)建和實(shí)體類,Spring中.S2SHAction依賴的實(shí)體類還是要通過(guò)Struts器賦值,實(shí)體類經(jīng)常是通過(guò)程序賦值和而非依賴注入賦值Bean的初始化,和銷毀方publicpublicvoid }publicvoid }@Test//測(cè)試@Test//測(cè)試initpublicvoidtest04(){ClassPathXmlApplicationContextcontext=new }中default-init-method="init"default-destroy-Bean的周期總ClassPathXmlApplicationContextclose()destory方法ApplicationContextclose()方法,需要強(qiáng)轉(zhuǎn)為具體的實(shí)現(xiàn)類才可以調(diào)用singleton時(shí)才會(huì)有效)依賴注入的兩種Set注<bean<bean.ssh.c.StudentServiceImpl"lazy-<propertyname="studentDao"ref="studentDao"<beanid="studentDao" 構(gòu)造注通過(guò)參數(shù)編號(hào)指定第一個(gè)參數(shù)編號(hào)為0<beanid="student" <constructor-argindex="1"value="admin"<constructor-argindex="0"value="1"<constructor-argindex="2"value="19"<constructor-argname="sname"value="admin"<constructor-argname="sid"value="1"<constructor-argname="sage"value="19"<beanid="student"復(fù)雜類型注向集合注publicpublicclassCollectionTestprivateString[]SetprivateSet<String>ListprivateList<Date>MapprivateMap<String,Student>PropertiesprivatePropertiespublicList<Date>getLists()return}publicvoidsetLists(List<Date>lists)this.lists=}publicMap<String,Student>getMaps()return}publicvoidsetMaps(Map<String,Student>maps)this.maps=}publicString[]getStrs()return}publicvoidsetStrs(String[]strs)this.strs=}publicSet<String>getSets()return}publicvoidsetSets(Set<String>sets)this.sets=}publicPropertiesgetPros()return}publicvoidsetPros(Propertiespros)s=}}<beanid="collectionTest"<beanid="collectionTest" <property<propertydate為日期bean的id<ref<property<property<entrykey="a"value-ref="student"<property<prop<prop<beanid="date"class="java.util.Date"加載外部資 <property,<!--配置文件相同的時(shí)候后面的會(huì)覆蓋前面的<context:property-ceholder>加 由于Property SpringStruts整SpringAction,Action→Service→Dao之間的解耦整合方1:ActionSpring容publicclasspublicclassStudentAction{ApplicationContextcontext=new//privateStudentService通過(guò)set方式,publicvoidsetStudentService(StudentServicestudentService)this.studentService=}},了大量的系統(tǒng)資源,其實(shí)Spring配置文件只需要加載一次即可,存放到項(xiàng)目的公共區(qū)域Application內(nèi)置對(duì)象中,bean的時(shí)候獲取即可整合方2:Spring來(lái)管Spring配置文件<context- Springstruts2-spring-plugin-.jarSpring<!--重新設(shè)置了創(chuàng)建Action的工廠類,此類會(huì)到Spring容器中取創(chuàng)建--<beantype="com.opensymphony.xwork2.ObjectFactory"class="org.apache.struts2.spring.StrutsSpringObjectFactory"/><!--MaketheSpringobjectfactorytheautomaticdefault-<constantname="struts.objectFactory"value="spring"<actionname="studentAction"class="studentAction"StrutsAction<actionname="studentAction"class="studentAction"設(shè)計(jì)模模式介模式即Pattern常用的設(shè)計(jì)模式之一.模式的主要作用是為其他對(duì);()角色:角色內(nèi)部含有對(duì)真實(shí)的,從而可以在任何時(shí)候操作真實(shí)對(duì)象角色提供一個(gè)與真實(shí)角色相同的接口,以便可以在任何時(shí);某個(gè)操作,而不是單純地將調(diào)用傳遞給真實(shí)對(duì)象;基于接口的靜類,來(lái)完成Session事務(wù)的提交、回publicclass implementsSessionprivateSessionsession=null;publicSession (Sessionsession){thisthis.session=}publicvoidbegin(){}publicvoidrollback(){}publicvoidsave(Studentstudent)try}catch(Exceptione)}finally}}publicvoidcommit(){}}基于繼承的靜classclasspublicvoidSystem.out.println("-----真實(shí)的業(yè)務(wù)邏 }}publicclassSonextendsFather{publicvoidtest()System.out.println("----執(zhí)行某些代 System.out.println("----執(zhí)行某些代 }publicstaticvoidmain(String[]args){Sonson=newSon();}}靜態(tài)總口或者是繼承相同父類,只能某種類型的對(duì)象,靜態(tài)存在一個(gè)問(wèn)題:當(dāng)我們?cè)诒坏念愔性黾恿艘粋€(gè)方法類中也要增加相應(yīng)方法,性比較,動(dòng)動(dòng)態(tài)介紹在運(yùn)行的時(shí)候通過(guò)被類的特征(獲取被類的接口、類型等)來(lái)動(dòng)態(tài)創(chuàng)建對(duì)象.這種機(jī)制稱為動(dòng)態(tài),可以解決靜態(tài)范圍有限制,難的缺點(diǎn).動(dòng)態(tài)有基于JavaJDK面向接口的方式和基于繼承原理的CGLIB方式APIpublicstaticObject Class<?>[]interfaces,InvocationHandlerh)publicstaticObject Class<?>[]interfaces,InvocationHandlerh)throws返回一個(gè)指定接口 類實(shí)例,該接口可以將方法調(diào)用指派到指定的調(diào)用處理程序 publicinterfacepublicinterfaceInvocationHandler是實(shí)例的調(diào)用處理程序?qū)崿F(xiàn)的接口 進(jìn)行編碼并將其指派到它的調(diào)用處理程序的invoke方法Object ,Methodmethod,Object[]在實(shí)例上處理方法調(diào)用并返回結(jié)案例演*演示基于JDK*Subject為*類,根據(jù)此類的信息通類publicclassSubjectimplementsISubjectpublicvoidtest()System.out.println("-----真實(shí)的業(yè)務(wù)邏 }publicStringtest2(intage,Stringname){ 為:"+age+" 為:"+name);return"test2";}publicstaticvoidmain(String[]args){ISubjectsubject =(ISubject) .getClassLoader(),newInvocationHandler()

publicObject ,Object[]param)throwsThrowable采用,動(dòng)態(tài)生成 對(duì)象 類的每個(gè)方法都會(huì)動(dòng)跳轉(zhuǎn)到此方法(invoke)中直接 )會(huì)死循環(huán)因 .toString()又會(huì)直接進(jìn)行invoke()方中final的,不能被重

但是可 .getClass(),因?yàn)榇薵etClassmethod:真實(shí)的業(yè)務(wù)邏輯方法,可以通過(guò)invoke調(diào)用param:當(dāng)前method 類為為

System.out.println(" 類的業(yè)務(wù)邏輯方法為:"if(param!=null)System.out.println("當(dāng)前業(yè)務(wù)邏輯方法的參for(Objecto:param){}}return} .test2(1,}}}類publicstaticObject Instance(ClassLoaderClass<?>[]interfaces,InvocationHandlerh)throws{nullif(h==null)thrownew}//根據(jù)傳入了類加載器,接口返回 類的ClassClasscl=get Class(loader,interfaces);try{//privatefinalstaticClass[]constructorParams//{InvocationHandler.classConstructorcons=//通過(guò)構(gòu)造方法創(chuàng)建 類,并且把h傳入到 類理有h而且調(diào)用 類的每一個(gè)方法都會(huì)跳轉(zhuǎn)到h.invoke中)return(Object)cons.newInstance(newObject[]{h}Instance類publicstaticObject Instance(ClassLoaderClass<?>[]interfaces,InvocationHandlerh)throws{nullif(h==null)thrownew}//根據(jù)傳入了類加載器,接口返回 類的ClassClasscl=get Class(loader,interfaces);try{//privatefinalstaticClass[]constructorParams//{InvocationHandler.classConstructorcons=//通過(guò)構(gòu)造方法創(chuàng)建 類,并且把h傳入到 類理有h而且調(diào)用 類的每一個(gè)方法都會(huì)跳轉(zhuǎn)到h.invoke中)return(Object)cons.newInstance(newObject[]{h}Instance源碼如下使用實(shí)現(xiàn)Session事務(wù)提publicstaticSessiongetSession()throwsHibernateException{Sessionsession=(Session)threadLocal.get();ifpublicstaticSessiongetSession()throwsHibernateException{Sessionsession=(Session)threadLocal.get();if(session==null||!session.isOpen())if(sessionFactory==null)}session=(sessionFactory!=null):}return new}實(shí)現(xiàn)不同接口類型的StudentSerive,GradeService*類,功publicclassMyInvocationHandlerimplements{//可 任何的類型,這些類型只 的功能相同就可以使用同一類privateObject//通過(guò)構(gòu)造方法把 對(duì)象傳入其publicMyInvocationHandler(Object}//權(quán)限驗(yàn)證的方法,publicvoidSystem.out.println("----權(quán)限驗(yàn)證功 }//日志方法,publicvoidSystem.out.println("-----日志功 } publicObjectinvoke(Object ,Methodmethod,Object[]throwsThrowable{Objectobj=null;obj=method.invoke(object,//如果滿足條件,}else////obj=method.invoke(object,//}return}}動(dòng)態(tài)總結(jié)JDK的動(dòng)態(tài)有個(gè)缺點(diǎn),那就是不能對(duì)類進(jìn)行,只能對(duì)接口進(jìn)行,想象一下如果項(xiàng)目做二次升級(jí),則并不是前面的業(yè)務(wù)邏輯類都采用了面向接口編程,那么將無(wú)法CGLib動(dòng)態(tài)介基于CGLib的實(shí)現(xiàn):CGLIB是一個(gè)開(kāi)源的動(dòng)態(tài)框架,它的出現(xiàn)補(bǔ)充了自帶的不能對(duì)類實(shí)現(xiàn)動(dòng)態(tài)的問(wèn)題classclasspublicvoidSystem.out.println("-----真實(shí)的業(yè)務(wù)邏 }}publicclassSonextendsFather{publicvoidtest()System.out.println("----執(zhí)行某些代 System.out.println("----執(zhí)行某些代 }publicstaticvoidmain(String[]args){Sonson=newSon();}}----執(zhí)行某----執(zhí)行某些代碼----執(zhí)行某些代碼子類繼承了父類的方法,在子類中實(shí)現(xiàn)功能:但這種方式的缺點(diǎn)更明顯,那就是只能對(duì)BusinessProcessImpl進(jìn)行,與包裝的模式相比大大縮小了范圍,但是如果我們能根據(jù)父類動(dòng)態(tài)的生成子類的話,可以在父類沒(méi)有接口的情況下也能解決動(dòng)態(tài)的問(wèn)題,CGLibCglib實(shí)現(xiàn)動(dòng)publicpublicclassimplementsMethodInterceptorprivateObject@param@param**@parampublicObjectintercept(Objectarg0,Methodarg1,Object[] arg3)throwsThrowable{returnnull;}privateObjectcreatePorxyInstatnce(Objectobject)//cglib使用該類創(chuàng)建目標(biāo)對(duì)象的 Enhanceren=newEnhancer();//設(shè) 處理程//返回被創(chuàng)建 return}publicstaticvoidmain(String[]args){ =newCglib yInstatnce(newBusinessProcessImpl());}}差不多 InvocationHandlerinvokAPI中有這么一段:General-purposeEnhancercallbackwhichprovidesfor"around也就是說(shuō)生成的這個(gè)方法連接會(huì)到EnhancercallbackEnhanceren=newEnhancer();//設(shè) 處理程GeneratesdynamicsubclassestoenablemethodGeneratesdynamicsubclassestoenablemethodinterception.ThisclassstartedasasubstitutethethestandardsupportincludedwithJDK1.3,butonethatallowedtheproxiesextendaconcretebaseclass,inadditiontoimplementinginterfaces.Thedynamicallysubclassesoverridethenon-finalmethodsofthesuperclassandhavehookswhichcallbacktouser-definedinterceptorimplementations.類,這樣才可以生成子類類),setCallback//JDK//JDK.是publicObjectintercept(Objectarg0,Methodarg1,Object[]arg2, arg3)throwsThrowable{//TODOAuto-generatedmethodstub arg1.invoke(targetobject,return}CGLIB完成方法日志和權(quán)限驗(yàn)證功CGlib:支持沒(méi)有接口 方式,原理publicclass implementsMethodInterceptor//用 類對(duì)privateObject//在創(chuàng)建CGlib的時(shí)候把 的對(duì)象傳入進(jìn)public (Object}//通過(guò)enhancer生 類,也就是 類的子publicObjectcreateCGlib Enhancerenhancer=newEnhancer();//設(shè) 類信息 類是父類, 類是子//設(shè)置回調(diào)對(duì)象,此對(duì)象returnenhancer.create();}//權(quán)限驗(yàn)證的方法,publicvoidSystem.out.println("----權(quán)限驗(yàn)證功 }//日志方法,publicvoidSystem.out.println("-----日志功 }publicpublicObjectintercept(Objectobject,Methodmethod,Object[]args, )throwsThrowable{ Objectobj=method.invoke(object,//如果滿足條件,}else////obj=method.invoke(object,//}return}}CGLIB總結(jié)CGLIBfinal要求類不能是final的,要的方法要是非final、非static、非privateSpring的AOP就是基于和CGLIB兩種方式來(lái)生成動(dòng)態(tài)的.會(huì)根據(jù)是否有接口智SpringAOP面向切面編程(重要Spring在運(yùn)行期創(chuàng)建,不需要特殊的編譯器。spring有兩種方式若目標(biāo)對(duì)象實(shí)現(xiàn)了若干接口,spring就會(huì)使用JDK動(dòng)態(tài)若目標(biāo)對(duì)象沒(méi)有實(shí)現(xiàn)任何接口,spring就使用CGLIB庫(kù)生成目標(biāo)對(duì)象的子AOP相關(guān)概念A(yù)spect(切面指橫切性關(guān)注點(diǎn)的抽象即為切面,它與類相似,只是兩者的關(guān)注點(diǎn)不一樣,類是對(duì)物體特征的抽象,而切面是橫切性關(guān)注點(diǎn)的抽象joinpoint(連接點(diǎn)所謂連接點(diǎn)是指那些被到的點(diǎn)。在spring中,這些點(diǎn)指的是方法,因?yàn)镻ointcut(切入點(diǎn)所謂切入點(diǎn)是指我們要對(duì)那些joinpoint進(jìn)行的

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論