通过dubbo获取某个服务报错,但单元测试也能通过,其他服务正常,调试了半天,很是纳闷,异常如下:
Error creating bean with name 'common-service': FactoryBean threw exception on object creation; nested exception is java.lang.RuntimeException: java.io.IOException: invalid constant type: 18] with root cause
java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
at javassist.bytecode.ConstPool.read(ConstPool.java:970)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:716)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:103)
at javassist.CtClassType.getClassFile2(CtClassType.java:190)
at javassist.CtClassType.subtypeOf(CtClassType.java:303)
at javassist.CtClassType.subtypeOf(CtClassType.java:318)
at javassist.compiler.MemberResolver.compareSignature(MemberResolver.java:247)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:119)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:96)
at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:704)
at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:681)
at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:156)
at javassist.compiler.ast.CallExpr.accept(CallExpr.java:45)
at javassist.compiler.JvstTypeChecker.atCastToWrapper(JvstTypeChecker.java:125)
at javassist.compiler.JvstTypeChecker.atCastExpr(JvstTypeChecker.java:97)
at javassist.compiler.ast.CastExpr.accept(CastExpr.java:54)
at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:241)
at javassist.compiler.CodeGen.compileExpr(CodeGen.java:228)
at javassist.compiler.CodeGen.atReturnStmnt2(CodeGen.java:597)
at javassist.compiler.JvstCodeGen.atReturnStmnt(JvstCodeGen.java:424)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:362)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:390)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:354)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.MemberCodeGen.atTryStmnt(MemberCodeGen.java:203)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:366)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:291)
at javassist.compiler.CodeGen.atMethodDecl(CodeGen.java:273)
at javassist.compiler.ast.MethodDecl.accept(MethodDecl.java:43)
at javassist.compiler.Javac.compileMethod(Javac.java:168)
at javassist.compiler.Javac.compile(Javac.java:94)
at javassist.CtNewMethod.make(CtNewMethod.java:73)
at javassist.CtNewMethod.make(CtNewMethod.java:44)
at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:281)
at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:256)
at com.alibaba.dubbo.common.bytecode.Wrapper.makeWrapper(Wrapper.java:239)
at com.alibaba.dubbo.common.bytecode.Wrapper.getWrapper(Wrapper.java:101)
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:290)
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:159)
at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1590)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
异常原因:
javasist冲突,dubbo中自动引入javasist-3.2.0.GA.jar
struts-core中引入了javasist-3.1.1.0.GA.jar
解决办法:
<!-- struts -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.24</version>
<exclusions>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
解决方式: