加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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

(2016-08-10 15:05:03)
分类: JAVA
今天在用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)
http://s7/mw690/001KZvomzy73WkNnUkma6&690cannot be cast to&nbs" TITLE="org.springframework.web.filter.CharacterEncodingFilter cannot be cast 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()); 
    }
}

http://s9/mw690/001KZvomzy73Wlj80Qgf8&690cannot be cast to&nbs" TITLE="org.springframework.web.filter.CharacterEncodingFilter cannot be cast 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

http://s1/mw690/001KZvomzy73Wlrte3S50&690cannot be cast to&nbs" TITLE="org.springframework.web.filter.CharacterEncodingFilter cannot be cast to&nbs" />

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

http://s4/mw690/001KZvomzy73WlBmKm713&690cannot be cast to&nbs" TITLE="org.springframework.web.filter.CharacterEncodingFilter cannot be cast 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

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有