Spring AOP CGLib报个这错java.lang.reflect.InvocationTargetException-->null
我搞了两天了,都不知道为什么,现在在线等等高手指点。谢谢了,急啊。
异常:
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at spring.AOPInstrument.getInstrumentedClass(AOPInstrument.java:28)
at spring.CGLibTest.main(CGLibTest.java:15)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 4 more
Caused by: java.lang.SecurityException: class "spring.MessageWriter$$EnhancerByCGLIB$$b58bc1ae"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:611)
at java.lang.ClassLoader.defineClass(ClassLoader.java:532)
... 10 more
Exception in thread "main" 
代码如下:
1.一个以后被代理的类public class MessageWriter { public void writeMessage()
{
System.out.print("World");
}

}
2.实现这个接口的一个“拦截器”import net.sf.cglib.proxy.MethodInterceptor;public class AOPInstrument implements MethodInterceptor { //private Logger log=Logger.getLogger(AOPInstrument.class);

private Enhancer enhancer=new Enhancer();

public Object getInstrumentedClass(Class clz)
{
Object proxy;
enhancer.setSuperclass(clz);
enhancer.setCallback(this);

proxy=enhancer.create();
return proxy;
}

public Object intercept(Object obj, Method method, Object[] methodParameters,
MethodProxy methodProxy) throws Throwable {

System.out.print("Hello ");
Object result=methodProxy.invokeSuper(obj, methodParameters);
System.out.print("!");

return result;
}}3.测试类public class CGLibTest { /**
 * @param args
 */
public static void main(String[] args) {
AOPInstrument aopIns=new AOPInstrument();
MessageWriter writer=(MessageWriter)aopIns.getInstrumentedClass(spring.MessageWriter.class);
writer.writeMessage(); }}

解决方案 »

  1.   

    还搞这  直接搞@aspectj吧
      

  2.   

    那个我也在学习中。但我用@AspectJ做时,面向接口的没问题,但是面向类的就不行,也是报与CGLib相关的错误。所以我想把CGLib学习,搞明白一下。
    Aop 一个是Proxy代理,别一个是CGLib代理。
    而这个CGLib总做不对。请高手指点。谢谢
      

  3.   

    为什么没有来帮帮呢
    运行程序时,总报下面的错:
    java.lang.reflect.InvocationTargetException-->null
      

  4.   

    System.out.print("Hello ");if (method.getName().equals((String)methodParameters[1])) {        
    Object result=methodProxy.invokeSuper(obj, methodParameters);
    } System.out.print("!");
      

  5.   


    Caused by: java.lang.SecurityException: class "spring.MessageWriter$$EnhancerByCGLIB$$b58bc1ae"'s signer information does not match signer information of other classes in the same package你把你的所有class清除掉,重新编译一遍
      

  6.   

    我删除后,又报这个错了。真奇怪啊。java.lang.NoClassDefFoundError: spring/CGLibTest
    Exception in thread "main" 
      

  7.   

    并且不行啊。我重新生成了class文件,还是报那个错啊。
      

  8.   

    谁来帮帮我啊。。Thanks God...
      

  9.   

    我也有同样的问题。
    lz解决了告诉我一下
    [email protected]谢谢了