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

分类: 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&690cannotbe 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&690cannotbe 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&690cannotbe 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&690cannotbe 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
严重: Exception starting filter springEncoding
java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter
http://s7/mw690/001KZvomzy73WkNnUkma6&690cannot
这个应该是版本冲突,我参照了网上的说是和 tomcat 里面的servlet冲突,仍没有解决这个问题.
首先可以确认的是jar 包冲突,但是每个项目使用的jar 都不一样,冲突的情况各不相同,不同用一个笼统的方法,我们应该从源头去排查.
通过 单元测试便可以将jar加载路径显示出来,这样变知道是哪个jar 冲突,直接解决问题.
public class TestRest {
}
http://s9/mw690/001KZvomzy73Wlj80Qgf8&690cannot
便打成路径:
path:/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
,
这样变知道是 avro-tools.jar 包和servlet-api.jar 冲突了,
然后修改 pom.xml:
http://s4/mw690/001KZvomzy73WlBmKm713&690cannot
再次运行便可以了.
参考:
http://stackoverflow.com/questions/15715864/opensessioninviewfilter-cannot-be-cast-to-javax-servlet-filter
http://blog.csdn.net/wenguang_hz/article/details/46227275