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

I port the application to JBoss 7, where all the dependencies were in "JBOSS_HOME/server/default/lib" (JBoss 4). I turned on lib "servlet.jar" (javax.servlet. *), However, by installing the Global module for JBoss 7 (modules.xml, stand-alone .xml, jboss-deployment-structure.xml in military files), the libraries are usually loaded by JBoss.

When JBoss 7 tries to run filters, I get the following exception:

 15:09:15,222 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RegistrarValorDolar]] (MSC service thread 1-2) Exception starting filter cripto: java.lang.ClassCastException: cenpra.com.sigtec.business.utilities.SessionFilter cannot be cast to javax.servlet.Filter at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:] at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_15] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_15] at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_15] 

Trying to remove the "servlet.jar" library from Global Modules, try to have the server load its own classes using the internal banner, I got the ClassNotFoundException class of javax.servlet.Filter class.

  • I want to use global modules, since I need to reuse many libraries.
+4
source share
1 answer

Your class path is polluted with several different versions of javax.servlet.Filter . A class that is loaded by the X class loader (for example, one that is responsible for the container's inner classes) is not the same class when it is loaded by the Y class loader (for example, responsible for the Webapp classes).

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

This is at least wrong. It is assumed that this is already provided by the target servlet container (this is JBoss in your case). You absolutely must not provide libraries specific to servletcontainer together with webapp in your /WEB-INF/lib folder. This would only end if the path class failed because they take precedence over the class than the one provided by the servletcontainer itself, and thus conflict with the inner servletcontainer classes, which in turn use their own servletcontainer classes.

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

This is a common starter error in a careless attempt to fix the crawl errors / errors on the javax.servlet API that they encounter in their IDE. It had to be solved in different ways. Essentially, you need to tell the IDE to associate the web project with this target container. Then, the IDE will automatically perform the necessary magic of the build path.

See also:

+8
source

All Articles