EJB 3.0之拦截器例子

使用拦截器可以对session bean 当中的所有的方法进行监听,直到发现执行了某个方法之后就触发了执行后的语句。
/**
 * 
 */
package com.ejb3.session;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

/**
 * @author zhouxingqi8@gmail.com
 * @Time 2010-12-16
 */
public class HelloIntercepter {
	@AroundInvoke
	public Object log(InvocationContext ic) {
		try {
			if (ic.getMethod().getName().equals("sayHello")) {

				System.out.println("SayHello() Method is invoked....");

			}
			if (ic.getMethod().getName().equals("sayBye")) {

				System.out.println("SayBye() method is Invoked ...");

			}
			return ic.proceed();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}

}

使用他我们可以在监听方法后选择自己的其他业务的实现

你可能感兴趣的:(bean,ejb,Gmail)