Spring_DynamicProxy

Dynamic Proxy of Spring:
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class SecurityHandler implements InvocationHandler{

	private Object targetObj;
	
	
	public Object newProxy(Object targetObj) {
		this.targetObj = targetObj;
		return Proxy.newProxyInstance(targetObj.getClass().getClassLoader() ,
				 					  targetObj.getClass().getInterfaces() ,
				 					  this);
	}
	
	//实现了IncocationHandler接口,里面的一个方法.
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		this.checkSecurity();
		Object result = null;
		result = method.invoke(this.targetObj, args);
		return result;
	}	
	
        //check security method
	private void checkSecurity() {
		System.out.println("-----------------SecurityHandler.checkSecurity()--------------");
	}
}

你可能感兴趣的:(java,spring,Security)