Spring configuration file:
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5. XSD Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2 .5.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop-2.5.xsd "
> <Aop:aspectj-autoproxy/> <BeanID= "Personservice"class= "Cn.itcast.service.impl.PersonServiceBean"></Bean> <BeanID= "Aspetbean"class= "Cn.itcast.service.MyInterceptor"/> <Aop:config> <Aop:aspectID= "ASP"ref= "Aspetbean"> <Aop:pointcutID= "Mycut"expression= "Execution (* cn.itcast.service). *.*(..))"/> <Aop:beforePointcut-ref= "Mycut"Method= "Doaccesscheck"/> <aop:after-returningPointcut-ref= "Mycut"Method= "Doafterreturning"/> <aop:after-throwingPointcut-ref= "Mycut"Method= "Doafterthrowing"/> <Aop:afterPointcut-ref= "Mycut"Method= "Doafter"/> <Aop:aroundPointcut-ref= "Mycut"Method= "Dobasicprofiling"/> </Aop:aspect> </Aop:config></Beans>
Cut:
PackageCn.itcast.service;ImportOrg.aspectj.lang.ProceedingJoinPoint;/*** Facets **/ Public classMyinterceptor { Public voidDoaccesscheck () {System.out.println ("Pre-notification"); } Public voiddoafterreturning () {System.out.println ("Post Notification"); } Public voidDoafter () {System.out.println ("Final Notice"); } Public voiddoafterthrowing () {System.out.println ("Exception Notification"); } PublicObject dobasicprofiling (Proceedingjoinpoint PJP)throwsthrowable {System.out.println ("Access Method"); Object result=pjp.proceed (); System.out.println ("Exit Method"); returnresult; } }
Spring AOP (configuration file mode)