package com.zyl;
public class VegetalbeService
{
public void food()
{
System.out.print("切菜-->炒菜");
}
}
---------------------------------------
package com.zyl;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class ServiceDecorator implements MethodInterceptor
{
public Object invoke(MethodInvocation invocation)throws Throwable
{
System.out.print("买菜-->洗菜-->");
Object obj=invocation.proceed();
System.out.print("-->上菜");
return obj;
}
}
-------------------
package com.zyl;
import org.springframework.aop.framework.ProxyFactory;
public class Vegetable
{
public static void main(String[] args)
{
VegetalbeService target=new VegetalbeService();
ProxyFactory factory=new ProxyFactory();
factory.addAdvice(new ServiceDecorator());
factory.setTarget(target);
VegetalbeService proxy=(VegetalbeService)factory.getProxy() ;
proxy.food();
}
}
--------------------------------------------------------
运行结果:
买菜-->洗菜-->切菜-->炒菜-->上菜
spring简单前置通知、后置处理
原创
©著作权归作者所有:来自51CTO博客作者mb6444ed45406a4的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:hibernate 的简单创建
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Spring事件处理机制的认识
Spring事件处理机制的认识
事件监听器 Spring