环绕增强
public class GreetingInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Object[] args = methodInvocation.getArguments();
String clientName = (String)args[0];
System.out.println("How are you!Mr."+clientName+".");
Object obj = methodInvocation.proceed();
System.out.println("Please enjoy yourself");
return null;
}
}
<bean id="greetingAround" class="com.smart.advice.GreetingInterceptor"/>
<bean id="waiter2" class="org.springframework.aop.framework.ProxyFactoryBean"
p:proxyInterfaces="com.smart.advice.Waiter"
p:interceptorNames="greetingAround"
p:target-ref="target"/>