`
java_frog
  • 浏览: 243852 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring简单前置通知、后置处理。

阅读更多
package com.ghr;

public class VegetalbeService 
{
	public  void food() 
	{
		System.out.print("切菜-->炒菜");
	}

}



package com.ghr;

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.ghr;

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();
		
	}
	
}

附有所需要的几个jar包,运行结果:
买菜-->洗菜-->切菜-->炒菜-->上菜
  • asm.jar (25.7 KB)
  • 下载次数: 1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics