ServletDispatcher cannot be cast to Javax.servlet.Servlet exception in my spring project

前端 未结 2 1622
-上瘾入骨i
-上瘾入骨i 2020-12-06 05:36

While starting tomcat server I am getting an exception

SEVERE: Servlet /MavenWeb threw load() exception
java.lang.ClassCastException: org.springframework.we         


        
2条回答
  •  Happy的楠姐
    2020-12-06 05:50

    In my case it wasn't a problem with the libraries. I was changing a Standard Servlet to be implemented with Spring, so I followed these instructions, that I paraphrase here just in case the page goes down later:

    1. Implement org.springframework.web.HttpRequestHandler instead of extending javax.Servlet

      public class MyServlet implements HttpRequestHandler {

    2. Created the bean in the applicationContext.xml (I did it in the dispatcher-servlet.xml)

    3. Specify the servlet in the Web.xml, changing the old class (com.package.to.MyServlet) to Spring HttpRequestHandlerServlet.

      MyServlet org.springframework.web.context.support.HttpRequestHandlerServlet MyServlet /MyServlet

    I had to do an additional step to avoid a FileNotFoundException about applicationContext.xml doing the following in the web.xml

    contextConfigLocation /WEB-INF/dispatcher-servlet.xml org.springframework.web.context.ContextLoaderListener

提交回复
热议问题