手写spring框架的时候,在JdkDynamicAopProxy的时候报了Method threw 'java.lang.ClassCastException' exception. Cannot evaluate com.sun.proxy.$Proxy5.toString()
在我执行完这一行的时候报了上面的错误
手写spring框架的时候,在JdkDynamicAopProxy的时候报了Method threw 'java.lang.ClassCastException' exception. Cannot evaluate com.sun.proxy.$Proxy5.toString()
在我执行完这一行的时候报了上面的错误
package com.john.mvcframework.aop;
import com.john.mvcframework.aop.intercept.JMethodInvocation;
import com.john.mvcframework.aop.support.JAdvisedSupport;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
/**
* @author : yumin
* @date : 2021-04-20 20:51
**/
public class JJdkDynamicAopProxy implements JAopProxy, InvocationHandler {
//AdvisedSupport中保存着aop的配置信息以及代理对象的信息
private JAdvisedSupport advised;
public JJdkDynamicAopProxy(JAdvisedSupport advised) {
this.advised = advised;
}
@Override
public Object getProxy() {
return getProxy(this.getClass().getClassLoader());
}
@Override
public Object getProxy(ClassLoader classLoader) {
return Proxy.newProxyInstance(classLoader, this.advised.getTargetClass().getInterfaces(), this);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, this.advised.getTargetClass());
JMethodInvocation mi = new JMethodInvocation(proxy, this.advised.getTarget(), method, args, this.advised.getTargetClass(), chain);
return mi;
}
}