AfterreturningEnhanced processing willAfter the target method is properly completed, it is woven.
Use @ afterreturning to specify the following two attributes:
① Pointcut/value: both are used to specify the cut-in expression corresponding to the start point.
②Returning: Specify a return value parameter name. The method for enhancing the processing definition can access the return value of the target method through the parameter name of this row.
Person. Java:
Public interface person {Public String sayhello (string name); Public void eat (string food );}
Chinese. Java:
Import Org. springframework. stereotype. component; @ componentpublic class Chinese implements person {@ overridepublic void eat (string food) {system. out. println ("I'm eating:" + food) ;}@ overridepublic string sayhello (string name) {system. out. println ("sayhello method executed"); Return name + "Hello, Spring AOP ";}}
Afterreturningadvicetest. Java:
Import Org. aspectj. lang. annotation. afterreturning; import Org. aspectj. lang. annotation. aspect;/*** define a plane ** @ author administrator **/@ aspectpublic class afterreturningadvicetest {@ afterreturning (returning = "RVT", pointcut = "execution (* COM. bean. *. *(..)) ") Public void log (Object RVt) {system. out. println ("Return Value of the target method:" + RVt); system. out. println ("log simulation function... ");}}
Bean. xml:
<? XML version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "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" xmlns: Tx = "http://www.springframework.org/schema/tx" xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <context: component-scan base-package = "com. bean "> <context: Include-filter type =" annotation "expression =" org. aspectj. lang. annotation. aspect "/> </Context: component-scan> <AOP: aspectj-autoproxy/> </beans>
Test. Java:
Public class test {public static void main (string [] ARGs) {applicationcontext CTX = new classpathxmlapplicationcontext ("bean. XML "); person P = (person) CTX. getbean ("Chinese"); system. out. println (P. sayhello ("James"); p. eat ("watermelon ");}}
Running console output: