---
title: "spring简单前置通知、后置处理。"
author: "java_frog"
date: "2009-02-09T01:24:46Z"
tags: []
slug: "spring"
draft: false
lastmod: "2009-02-09T01:25:50Z"
id: 325364
url: "https://java-frog.iteye.com/blog/325364"
---

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

```java
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;
		
	}

}
```



```java
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包,运行结果:
买菜-->洗菜-->切菜-->炒菜-->上菜