It is recommended to use annotations instead of XML
PackageOrg.zln.module.test3_aop.interceptor;ImportOrg.aspectj.lang.ProceedingJoinPoint;Importorg.aspectj.lang.annotation.*;/*** Created by Coolkid on 2015/6/6 0006.*//*declares that this is a facet*/@Aspect Public classMyinterceptor {/*declares the Pointcut defines the method to intercept method the body is empty, using an expression to describe which method is the Pointcut*/@Pointcut ("Execution (* org.zln.module.test3_aop.service.impl.personservicebean.* (..))") Private voidAnymethod () {}/*declaring a pre-notification*/@Before ("Anymethod ()") Public voidDoaccesscheck () {System.out.println ("Pre-notification"); } @After ("Anymethod ()") Public voidDoafter () {System.out.println ("Final Notice"); } @AfterThrowing (Pointcut= "Anymethod ()", throwing= "E") Public voiddoafterthrowing (Exception e) {System.out.println ("Exception Notification:" +e); } @Around ("Anymethod ()") PublicObject dobasicprofiling (Proceedingjoinpoint PJP)throwsThrowable {//if () {//determine if the user is in a permissionSystem.out.println ("Entry method")); /*executing a business bean method*/Object Result=pjp.proceed (); System.out.println ("Exit Method"); //} returnresult; }}/*Execution (* org.zln.module.test3_aop.service). *.*(..)) Describes the first * return value type, * represents any return value type Org.zln.module.test3_aop.service package name: The class under the sub-package also intercepts the second class, * represents the third * method of all classes, * represents all methods (..) Parameter of the method,: Represents any defined Anymethod method as the name of this pointcut execution (* org.zln.module.test3_aop.service.impl.personservicebean.* (..)) Instructions to intercept all methods of the Personservicebean class*/
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd "> <!--Open the AOP annotation parser - <Aop:aspectj-autoproxy/> <!--handing custom interceptors to spring management - <BeanID= "Myinterceptor"class= "Org.zln.module.test3_aop.interceptor.MyInterceptor"/> <BeanID= "PERSONSERVICEAOP"class= "Org.zln.module.test3_aop.service.impl.PersonServiceBean"/></Beans>
Spring's AOP