升级jdk8后系统报错解决:java.lang.RuntimeException: java.io.IOException: invalid constant type: 18

今天项目从jdk7升级到jdk8,Tomcat启动竟然报出这个运行时错误。

错误信息:java.io.IOException: invalid constant type: 18

2015-09-17 09:06:16:ERROR localhost-startStop-1 org.springframework.web.context.ContextLoader - Context initialization failed
java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
	at javassist.CtClassType.getClassFile2(CtClassType.java:203)
	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:318)
	at com.alibaba.dubbo.common.bytecode.Wrapper.makeWrapper(Wrapper.java:346)
	at com.alibaba.dubbo.common.bytecode.Wrapper.getWrapper(Wrapper.java:89)
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:426)
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:281)
	at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:242)
	at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:143)
	at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:109)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:327)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:941)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:475)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: invalid constant type: 18
	at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090)
	at javassist.bytecode.ConstPool.read(ConstPool.java:1033)
	at javassist.bytecode.ConstPool.(ConstPool.java:149)
	at javassist.bytecode.ClassFile.read(ClassFile.java:737)
	at javassist.bytecode.ClassFile.(ClassFile.java:108)
	at javassist.CtClassType.getClassFile2(CtClassType.java:190)
	... 65 more


解决方法:


网上查了一下有人说是javassist3.18.1以下版本在jdk8版本下不工作,而我使用的版本是3.12.1,果断更换到3.18.1版本后,启动依然不行!
又有网友说asm5以下的版本在jdk8下也不工作,而另一个已经停止更新的类库cglib,它的最新版本3.0最高只能支持到asm4,
所以最后的解决方法是:删除 cglib, asm 升级到5.0.4, javassist 升级到 3.18.0 以上,测试成功!


相关类库介绍:

ASM 是一个 Java 字节码操控框架。它能够以二进制形式修改已有类或者动态生成类。
ASM 可以直接产生二进制 class 文件,也可以在类被加载入 Java 虚拟机之前动态改变类行为。
ASM 从类文件中读入信息后,能够改变类行为,分析类信息,甚至能够根据用户要求生成新类。
CGlib(Code Generation Library)能够在程序运行的时候动态生成接口的实现类和继承于某个类的子类,它是依赖于ASM的。
Javassist是一个开源的分析、编辑和创建Java字节码的类库,能动态改变类的结构,或者动态生成类。

目前CGlib已经停止更新,Javassist已经取代了CGlib的功能。


你可能感兴趣的:(JavaWeb,异常解决)