final Object obj=Class.forName(value).newInstance();
if(id.endsWith("Service")){
Object proxyObj = Proxy.newProxyInstance(obj.getClass().getClassLoader(),obj.getClass().getInterfaces(),new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if("add".equals(method.getName()) || "regist".equals(method.getName())){
System.out.println("方法被代理了");
return method.invoke(obj, args);
}
return method.invoke(obj, args);
}
});
return proxyObj;
}
return obj;
网友评论