idea中tomcat的版本和项目代码的版本不一致导致的问题

[java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature] with root cause....

在解决这个问题的过程中,知道了LinkageError的错误一般和tomcat有关,查了有的说删除tomcat--webapp--项目--webINF--lib下的和tomcat有关的jar包,但是不知道是不是我理解错误:idea只要install重新打包就会再次产生新的lib,删除的jar包,重新出现,于是有看帖子说可以在pom文件中设置的范围:

1、test范围指的是测试范围有效,在编译和打包时都不会使用这个依赖

2、compile范围指的是编译范围有效,在编译和打包时都会将依赖存储进去

3、provided依赖:在编译和测试的过程有效,最后生成war包时不会加入,诸如:servlet-api,因为servlet-api,tomcat等web服务器已经存在了,如果再打包会冲突

4、runtime在运行的时候依赖,在编译的时候不依赖

显然这里用到的是provided,需要把和tomcat有关的添加scope,搜索tomcat就可以了。

idea中tomcat的版本和项目代码的版本不一致导致的问题_第1张图片

这个问题就解决了,觉得刚安装idea遇见跟多的问题是maven版本,maven仓库的问题,今天一天才解决这些问题,不知道该说什么,Java开发环境真的是不兼容的太多了。

你可能感兴趣的:(java错误)