Search code examples
javaspringservletsspring-mvcspring-mvc-initbinders

Extending The Spring Framework (Java) Servlet


I'm working on a Java web app that uses the Spring Framework (MVC). All my code is in controller files that are instantiated by the servlet. I would like to extend the servlet so that I can run some code in the init of the servlet; however, I'm very new to the Spring Framework and Java web development in general. I'm not sure how to extend the servlet, where I would put my derived servlet, etc. Can someone point me in the right direction on this?


Solution

  • Did you mean dispatcherServlet? you can just extends this servlet, re-config it in web.xml.

    <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>Your DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:/META-INF/springmvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>