????????Spring????????????Spring?????????????????IoC?????????AOP??????IoC??????????????????????Spring?????AOP??????????????????????AOP????????????????????????????????????????????????????AOP???????java????????????????????????java??????????????????
??????java????????????У??????????????????????? InvocationHandler(Interface)??????????? Proxy(Class)???????????????????????????????????????????????????????java??API??????????????????????????????????
????InvocationHandler:
????InvocationHandler is the interface implemented by the invocation handler of a proxy instance. Each proxy instance has an associated invocation handler. When a method is invoked on a proxy instance?? the method invocation is encoded and dispatched to the invoke method of its invocation handler.
?????????????????????????InvocationHandler?????????????????????????????????????handler????????????????????????????????????????????????????InvocationHandler??????? invoke ?????????е??á???????????InvocationHandler?????????????? invoke ??????
????Object invoke(Object proxy?? Method method?? Object[] args) throws Throwable
???????????????????????????????????????????????????????????
????Object invoke(Object proxy?? Method method?? Object[] args) throws Throwable
????proxy:????????????????????????????
????method:???????????????????????????????????????Method????
????args:?????????????????????????????????????
????????????????????????????????????????????и???????
????????????????????Proxy?????
????Proxy provides static methods for creating dynamic proxy classes and instances?? and it is also the superclass of all dynamic proxy classes created by those methods.
????Proxy?????????????????????????????????????????????????????????????????? newProxyInstance ?????????
????public static Object newProxyInstance(ClassLoader loader?? Class<?>[] interfaces??  InvocationHandler h)  throws IllegalArgumentException
????Returns an instance of a proxy class for the specified interfaces that dispatches method invocations to the specified invocation handler.
???????????????????????????????????????????????????????????????????????????????壺
????public static Object newProxyInstance(ClassLoader loader?? Class<?>[] interfaces?? InvocationHandler h) throws IllegalArgumentException
????loader:???????ClassLoader???????????????ClassLoader?????????????????????м???
????interfaces:???????Interface????????飬??????????????????????????????????????????????????????????????????????????????y??(???)????????????????????е??????
????h:???????InvocationHandler???????????????????????????????÷????????????????????InvocationHandler??????
?????????????????????????(??)??????????????????????????????????????????????
????????????????????Subject???????????????????????????
????public interface Subject
????{
????public void rent();
????public void hello(String str);
????}
???????????????????????????????????????????????????RealSubject??
????public class RealSubject implements Subject
????{
????@Override
????public void rent()
????{
????System.out.println("I want to rent my house");
????}
????@Override
????public void hello(String str)
????{
????System.out.println("hello: " + str);
????}
????}
???????????????????????????????????????????????????????????????? InvocationHandler ?????????????????????????????????
public class DynamicProxy implements InvocationHandler
{
//????????????????????????
private Object subject;
//    ??????????????????????????????
public DynamicProxy(Object subject)
{
this.subject = subject;
}
@Override
public Object invoke(Object object?? Method method?? Object[] args)
throws Throwable
{
//????????????????????????????Щ????????
System.out.println("before rent house");
System.out.println("Method:" + method);
//    ???????????????????????????????????????????????????handler?????invoke?????????е???
method.invoke(subject?? args);
//??????????????????????????????Щ????????
System.out.println("after rent house");
return null;
}
}