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?
-
1see: stackoverflow.com/questions/2006022/… and stackoverflow.com/questions/5419695/…DannyMo– DannyMo2013-07-18 23:16:27 +00:00Commented Jul 18, 2013 at 23:16
-
1Can you specify what you're trying to do? Maybe it can be achieved in a simpler wayCarlos Gavidia-Calderon– Carlos Gavidia-Calderon2013-07-19 01:47:56 +00:00Commented Jul 19, 2013 at 1:47
-
I would like to run a single background process which any request can pass long-term work to. See the 'Background Processing' section at [oreilly.com/catalog/jservlet/chapter/ch03.html].Trevor– Trevor2013-07-19 04:17:27 +00:00Commented Jul 19, 2013 at 4:17
Add a comment
|
1 Answer
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>
2 Comments
Trevor
I'm not familiar with defining code in an XML file. How would I add code to the derived servlet's init function? Is there no way to extend the dispatcherServlet using a traditional class file (.java)?
Yugang Zhou
Of course you can extend the DispatcherServlet. The answer is telling how to register your custom DispatcherServlet in the web container. Note the "Your DispatcherServlet".