CharacterEncodingFilter cannot be cast to javax.servlet.Filter 报错, 原因servlet-api.jar冲突 解决方案

来源:互联网 发布:炫酷黑客手机源码 编辑:程序博客网 时间:2024/06/05 00:09
今天在用Maven  运行 tomcat:run 进行项目热部署的时候, 出现如下错误:

严重: Exception starting filter springEncoding
java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
org.springframework.web.filter.CharacterEncodingFilter <wbr>cannot <wbr>be <wbr>cast <wbr>to&nbs

这个应该是版本冲突,我参照了网上的说是和 tomcat 里面的servlet冲突,仍没有解决这个问题.

首先可以确认的是jar 包冲突,但是每个项目使用的jar 都不一样,冲突的情况各不相同,不同用一个笼统的方法,我们应该从源头去排查.

通过 单元测试便可以将jar加载路径显示出来,这样变知道是哪个jar 冲突,直接解决问题.
public class TestRest {

    @Test 
    public void get(){ 
        URL url = Filter.class.getProtectionDomain().getCodeSource().getLocation(); 
        System.out.println("path:"+url.getPath()+"  name:"+url.getFile()); 
    }
}

org.springframework.web.filter.CharacterEncodingFilter <wbr>cannot <wbr>be <wbr>cast <wbr>to&nbs
便打成路径:

path:/D:/apache-maven-3.0.5-bin/repository/org/apache/avro/avro-tools/1.7.7/avro-tools-1.7.7.jar name:/D:/apache-maven-3.0.5-bin/repository/org/apache/avro/avro-tools/1.7.7/avro-tools-1.7.7.jar

org.springframework.web.filter.CharacterEncodingFilter <wbr>cannot <wbr>be <wbr>cast <wbr>to&nbs

这样变知道是 avro-tools.jar 包和servlet-api.jar 冲突了,
然后修改 pom.xml:
   
           org.apache.avro
           avro-tools
           1.7.7
           provided
       

org.springframework.web.filter.CharacterEncodingFilter <wbr>cannot <wbr>be <wbr>cast <wbr>to&nbs


再次运行便可以了.

参考:
http://stackoverflow.com/questions/15715864/opensessioninviewfilter-cannot-be-cast-to-javax-servlet-filter
http://blog.csdn.net/wenguang_hz/article/details/46227275
阅读全文
0 0
原创粉丝点击