记录一次Spring asm和jdk兼容性的采坑

  aluaa

    本人准备跑一个旧版本spring的java web项目,环境如下:
    jdk1.8.0_151
    spring 3.2.0

    catalina.out日志报错如下:

    ERROR [http-nio-8080-exec-6] - Context initialization failed
    java.lang.IllegalArgumentException
            at org.springframework.asm.ClassReader.<init>(Unknown Source)
            at org.springframework.asm.ClassReader.<init>(Unknown Source)
            at org.springframework.asm.ClassReader.<init>(Unknown Source)
            at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
            at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
            at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
            at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
            at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298)
            at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
            at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300)
            at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230)
            at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153)
            at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130)
            at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:285)
            at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
            at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
            at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
            at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
            at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
            at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
            at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
            at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
            at javax.servlet.GenericServlet.init(GenericServlet.java:158)
            at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
            at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
            at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
            at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
            at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
            at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
            at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Thread.java:748)
    

    google很久,最后在外网找到如下答案:
    imagepng

    意思是:可能是当前spring的版本和jdk版本不一致,要么升级spring,要么降jdk版本。由于该项目是基于jdk 1.7的,所以
    我试着把jdk从当前1.8降到1.7,报错不再出现,问题解决!