????????
?????????????AOP???????????????Spring?????????????????????ú??й????cross cutting concerns????AOP????????????????AOP??Spring???????????????????????????core java??????AOP??????????????????ü?????????????????????????λ???????У????????????????????????????????????μ??????????????????????????????????——?????????Spring?????????core Java???????????AOP????????????????????????????????????????core Java??????AOP?????????????AOP???????????????????????????????????й?Spring AOP??Java AOP?????о????????й???core Java?н??????е?????????AOP?????
????????????????AOP????????????Spring????????????????????????????????????Spring??????????AOP?????????????????Spring???????JDK proxy??CGlib??????????AOP???JDK dynamic proxy???????????????hook??????????????????????????в???????????????????????????????????????????y???????????????????????????????????????????????????????????????????????Щ????????????????????3???????????????????????core framework ??????????????????????????????????????????highjack????????ж????У????????????????????????????????????????????????????????????
????public interface Calculator {
????public int calculate( int a ?? int b);
????}
?????y??????????????£?
????public class CalculatorImpl implements Calculator {
????@Override
????public int calculate(int a?? int b) {
????return a/b;
????}
????}
?????????????????????????????????????????κθ?????????????????????У?鸚?????????????JDK dynamic proxy?????ɡ?
????public class SomeHandler implements InvocationHandler {
????// Code omitted for simplicity…..
????@Override
????public Object invoke(Object proxy?? Method method?? Object[] params) throws Throwable {
????// Your complex business validation and logic
????Object result = method.invoke(targetObject ??params);
????return result;
????}
????}
???????????????????????????JDK dynamic proxy????У?鸚???Ч????Ρ?
????public static void main(String[] args) {
????CalculatorImpl calcImpl = new CalculatorImpl();
????Calculator proxied = (Calculator)ProxyFactory.getProxy (Calculator.class?? calcImpl??
????new SomeHandler(calcImpl));
????int result = proxied.calculate(20?? 10);
????System.out.println("FInal Result :::" + result);
????}
???????????????????????????????InvocationHandler????????????????hooking implementation??????JDK???????????InvocationHandler????????????????????proxy instance?????????????????????