public interface Axe {
void chop();
}
public class StealAxe implements Axe {
@Override
public void chop() {
System.out.println("用钢斧砍柴。");
}
}
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class AxeProxyJdk implements InvocationHandler {
private Object delegate;
public Object getInstance(Object delegate) {
this.delegate = delegate;
return Proxy.newProxyInstance(
delegate.getClass().getClassLoader(),
delegate.getClass().getInterfaces(),
this
);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("我检查一下??");
Object result = method.invoke(delegate, args);
System.out.println("结束了e");
return result;
}
}
import money.dao.impl.DaoImpl;
import money.service.impl.ServiceImpl;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.BeanMapHandler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Axe proxy = (Axe) new AxeProxyJdk()
.getInstance(new StealAxe());
proxy.chop();
}
}