一个spring3.2的项目 从jdk1.7放到1.8的环境中编译,打开网页异常:spring jar包版本升级经历
背景:一个历史项目用的是 spring3.2 的版本,在jdk1.7中运行没有问题,但是如果在jdk1.8中运行就会报错
---浏览器中显示:
HTTP Status 500 - Servlet.init() for servlet springmvc_rest threw exception
HTTP Status 500 - Servlet.init() for servlet springmvc_rest threw exception type Exception report message Servlet.init() for servlet springmvc_rest threw exception description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet springmvc_rest threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause java.lang.IllegalArgumentException org.springframework.asm.ClassReader.<init>(Unknown Source) org.springframework.asm.ClassReader.<init>(Unknown Source) org.springframework.asm.ClassReader.<init>(Unknown Source) org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52) org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101) org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76) org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298) org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300) org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300) org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230) org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153) org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130) org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:285) org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223) org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745)
------------eclipse 中显示:
八月 31, 2017 4:08:48 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Allocate exception for servlet springmvc_rest
java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
八月 31, 2017 4:08:48 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Allocate exception for servlet springmvc_rest 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:1238) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:828) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
之前百度折腾过,说是spring 版本和jdk 冲突。要么就把spring 版本升级到4.0以上。本人下面的博客的第二点有说明:
http://www.cnblogs.com/rogge7/p/7241456.html
决定:心想总是要解决的,准备把spring相关的包升级到4以上的版本,那问题了,找jar包是个问题,找多少版本是个问题,相关连的包??
步骤:1、原来项目的jar包
如果去网上找?本地项目或仓库找? 一个个找感觉都不现实。想到一个方法,新建一个Maven项目,全部的导入相关的依赖包,把这些包导出来,替换到旧项目。
2、新建Maven项目, 添加添加相关jar(不懂百度)
Maven配置 和创建一个Maven项目 - 海蓝steven - 博客园 -- 5、添加jar包
http://www.cnblogs.com/rogge7/p/7272594.html
3、导出jar包
maven导出项目依赖的jar包 - java学习开发 - CSDN博客
http://blog.csdn.net/fendou123_love/article/details/46356823
导出到自定义目录中
在maven项目下创建lib文件夹(不创建也可以,自定义其它的文件夹名也可以),输入以下命令:
mvn dependency:copy-dependencies -DoutputDirectory=lib
maven项目所依赖的jar包都会复制到项目目录下的lib目录下
等待运行完成后,Maven项目下就会多了lib的文件夹
4、把旧项目的jar包换成新的就可以打开网页了。大功告成
拓展:Maven仓库估计没有配置远程的服务器,搜索的时候未能显示到jar包的其它版本(都是本地的)。待学习
==2017-11-13 18:18 把已经改造好的项目 从jdk1.8放到jdk1.7的环境运行: