异常错误记录

时间:2022-12-14 20:06:02

 

异常描述:

  启动Tomcat时,发生java.lang.ClassCastException: org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor cannot be cast to javax.servlet.Filter异常,初步分析为类转换不合适

 

详细信息:

严重: Exception starting filter openSessionInView
java.lang.ClassCastException: org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor cannot be cast to javax.servlet.Filter
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4958)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5652)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

 

异常的解决:

  最后发现,在web.xml中不小心将org.springframework.orm.hibernate5.support.OpenSessionInViewFilter写成了org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor,并且由于OpenSessionInViewInterceptor正好也是Spring的类,按住ctrl键编译器也有反应,没仔细看就以为正确了,因此好久才找出原因