解决:Tomcat启动报错:java.lang.ClassCastException: xxxFilter cannot be cast to javax.servlet.Filter

Tomcat启动报错:java.lang.ClassCastException: xxx.Filter cannot be cast to javax.servlet.Filter如下:

26-Apr-2020 09:38:33.269 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [xssFilter]
        java.lang.ClassCastException: xxx.filter.XssFilter cannot be cast to javax.servlet.Filter
                at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
                at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:106)
                at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4548)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5193)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
                at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:970)
                at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1841)
                at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
                at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
                at java.lang.Thread.run(Thread.java:748)

解决方案:
1.web.xml中进行Servlet的映射配置,与Servlet中用注解配置映射 不能共存(二选一)
2.我的是filter包导入错误导致

//import cn.hutool.core.lang.Filter; //导入错误(快捷键误导入)
import javax.servlet.Filter;

你可能感兴趣的:(Java,Java基础,问题汇集)