关于SpringMVC+Mybatis项目启动时,Tomcat抛出的Java heap space异常问题

现象

首先,我们先来看一个报错,这个异常是启动SpringMVC项目时,Tomcat抛出的:

三月 19, 2018 6:53:34 上午 org.apache.catalina.startup.ContextConfig processAnnotationsJar
严重: Unable to process Jar entry [org/apache/ibatis/javassist/bytecode/SignatureAttribute$TypeArgument.class] from Jar [jar:file:/D:/sts-bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance/wtpwebapps/investDecision/WEB-INF/lib/mybatis-3.4.0.jar!/] for annotations
java.io.EOFException
	at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
	at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:187)
	at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:159)
	at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.(FieldOrMethod.java:76)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:226)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:101)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1987)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1940)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1915)
	at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1876)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1145)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

三月 19, 2018 6:53:34 上午 org.apache.catalina.startup.ContextConfig processAnnotationsJar
严重: Unable to process Jar entry [org/apache/ibatis/javassist/bytecode/SignatureAttribute$TypeParameter.class] from Jar [jar:file:/D:/sts-bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance/wtpwebapps/investDecision/WEB-INF/lib/mybatis-3.4.0.jar!/] for annotations
java.io.EOFException
	at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
	at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:187)
	at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:159)
	at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.(FieldOrMethod.java:76)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:226)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:101)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1987)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1940)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1915)
	at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1876)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1145)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

三月 19, 2018 6:53:34 上午 org.apache.catalina.startup.ContextConfig processAnnotationsJar
严重: Unable to process Jar entry [org/apache/ibatis/javassist/bytecode/SignatureAttribute$TypeVariable.class] from Jar [jar:file:/D:/sts-bundle/pivotal-tc-server-developer-3.0.0.RELEASE/base-instance/wtpwebapps/investDecision/WEB-INF/lib/mybatis-3.4.0.jar!/] for annotations
java.io.EOFException
	at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
	at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:188)
	at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:159)
	at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.(FieldOrMethod.java:76)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:226)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:101)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1987)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1940)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1915)
	at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1876)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1145)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

三月 19, 2018 6:53:34 上午 org.apache.catalina.startup.HostConfig deployDescriptors
严重: Error waiting for multi-thread deployment of context descriptors to complete
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:188)
	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:498)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:394)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1439)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:282)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
	at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:347)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:933)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:868)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.OutOfMemoryError: Java heap space
	at org.apache.tomcat.util.bcel.classfile.Utility.swallowUnknownAttribute(Utility.java:156)
	at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:102)
	at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.(FieldOrMethod.java:76)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:226)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:101)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1987)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1940)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1915)
	at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1876)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1145)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1686)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	... 4 more


问题跟踪

Java heap space?堆内存溢出?啥情况,项目是我刚创建的,刚引入了几个jar包,居然创建失败了,而且还是内存溢出,先检查一下JVM的内存设置

关于SpringMVC+Mybatis项目启动时,Tomcat抛出的Java heap space异常问题_第1张图片


JVM参数使用的是STS默认的配置,堆内存上限为768M,难道启动一个SpringMVC+Mybatis的项目,768M内存还不够?没道理啊,赶紧百度一下。

在尝试过各种JVM内存配置后,统统无法解决当前问题,最后看到一篇博客

tomcat7在myeclipse中启动不了 出现严重: Error waiting for multi-thread deployment of directories to completehostConfig.deploy  

关于SpringMVC+Mybatis项目启动时,Tomcat抛出的Java heap space异常问题_第2张图片

这位兄弟为了解决问题,从学习JVM内存配置方案到放弃,最后将注意力放到jar包上,最终解决问题,启发了我

发现我的异常堆栈中,主要是提示ibatis的类无法加载,起初以为是内存不足的原因导致无法加载,然后尝试重新创建一个空的SpringMVC项目,不导入Mybatis的jar包,能正常启动,且内存使用仅有33MB,但是在导入了Mybatisjar包后却会报Java heap space错误,猜想可能是Mybatis包导致的Java heap space问题。


解决


在pom.xml中,我的springframework使用的是3.1.1.RELEASE版本,引入的Mybatis是3.4.0版本,Mybatis-spring的版本是1.3.0,根据 MvnRepository 显示,建议是spring版本是4.2.5,因此我尝试修改了mybatis版本,改成3.2.1,Tomcat就能正常启动了


总结

总的来说,其实就是引入的jar包版本不兼容导致的问题,至于为什么会报Java heap space问题,可能就是版本不兼容后产生的一系列后果,如同你只看到千里之堤毁于一旦,却不曾料定罪魁祸首竟是蚁穴。



你可能感兴趣的:(随笔)