ClassCastException: MyFilter cannot be cast to javax.servlet.Filter

前端 未结 1 1520
無奈伤痛
無奈伤痛 2020-12-21 02:32

I\'m migrating an application to JBoss 7, where all dependencies were in \"JBOSS_HOME/server/default/lib\" (JBoss 4). I included the lib \"servlet.jar\"

相关标签:
1条回答
  • 2020-12-21 03:05

    Your classpath is polluted with multiple different versioned javax.servlet.Filter classes. A class which is loaded by classloader X (e.g. the one responsible for container's internal classes) is not the same class when it's loaded by classloader Y (e.g. the one responsible for webapp's classes).

    I included the lib "servlet.jar" (javax.servlet.)

    This does at least not sound right. This is supposed to be already provided by the target servletcontainer (which is JBoss in your case). You should absolutely not provide servletcontainer-specific libraries along with the webapp in its /WEB-INF/lib folder. This would only end up in runtime classpath disaster because they get classloading precedence over the ones provided by the servletcontainer itself and thus conflicts with servletcontainer's internal classes which are in turn using servletcontainer's own classes.

    Get rid of servletcontainer-specific libraries in /WEB-INF/lib folder.

    This is a common starter's mistake in a careless attempt to fix/circumvent compilation errors on javax.servlet API which they face in their IDE. It should have been solved differently. To the point, you need to tell the IDE to associate the web project with the given target container. The IDE will then automatically do the necessary build path magic.

    See also:

    • How do I import the javax.servlet API in my Eclipse project?
    0 讨论(0)
提交回复
热议问题