在调用dubbo RPC时暴露的接口方法,不能用void getTest()这样定义方法,(这是dubbo的规则)否则在编译时就会提示错误,必须要定义为有返回参数的才能被通过例如:String getTest()这样就能被通过,下面为错误提示:(如果有兴趣可以研究哈源代码)
... 14 more
Caused by: java.lang.ClassFormatError: Method "<init>" in class com/alibaba/dubbo/common/bytecode/Wrapper0 has illegal signature "(V)V"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javassist.ClassPool.toClass2(ClassPool.java:1102)
at javassist.ClassPool.toClass(ClassPool.java:1083)
... 16 more
public Class<?> toClass(ClassLoader loader, ProtectionDomain pd)
{
if( mCtc != null )
mCtc.detach();
long id = CLASS_NAME_COUNTER.getAndIncrement();
try
{
CtClass ctcs = mSuperClass == null ? null : mPool.get(mSuperClass);
if( mClassName == null )
mClassName = ( mSuperClass == null || javassist.Modifier.isPublic(ctcs.getModifiers())
? ClassGenerator.class.getName() : mSuperClass + "$sc" ) + id;
mCtc = mPool.makeClass(mClassName);
if( mSuperClass != null )
mCtc.setSuperclass(ctcs);
mCtc.addInterface(mPool.get(DC.class.getName())); // add dynamic class tag.
if( mInterfaces != null )
for( String cl : mInterfaces ) mCtc.addInterface(mPool.get(cl));
if( mFields != null )
for( String code : mFields ) mCtc.addField(CtField.make(code, mCtc));
if( mMethods != null )
{
for( String code : mMethods )
{
if( code.charAt(0) == ':' )
mCtc.addMethod(CtNewMethod.copy(getCtMethod(mCopyMethods.get(code.substring(1))), code.substring(1, code.indexOf('(')), mCtc, null));
else
mCtc.addMethod(CtNewMethod.make(code, mCtc));
}
}
if( mDefaultConstructor )
mCtc.addConstructor(CtNewConstructor.defaultConstructor(mCtc));
if( mConstructors != null )
{
for( String code : mConstructors )
{
if( code.charAt(0) == ':' )
{
mCtc.addConstructor(CtNewConstructor.copy(getCtConstructor(mCopyConstructors.get(code.substring(1))), mCtc, null));
}
else
{
String[] sn = mCtc.getSimpleName().split("\\$+"); // inner class name include $.
mCtc.addConstructor(CtNewConstructor.make(code.replaceFirst(SIMPLE_NAME_TAG, sn[sn.length-1]), mCtc));
}
}
}
return mCtc.toClass(loader, pd);
}
catch(RuntimeException e)
{
throw e;
}
catch(NotFoundException e)
{
throw new RuntimeException(e.getMessage(), e);
}
catch(CannotCompileException e)
{
throw new RuntimeException(e.getMessage(), e);
}
}