PDA

View Full Version : using a standalone servlet with the DispatcherServlet


cable
Nov 17th, 2005, 12:05 PM
hey all,

i have a spring mvc application and i'd like to map a pre-existing servlet with my SimpleUrlHandlerMapping. the servlet in question is fairly trivial. it takes a Request, processes it and sends a redirect via the Response. i want to be able to manage the servlet under spring so i can inject a service dependency into it. ive attempted extending HttpServletBean and FrameworkServlet without much luck (and i suspect thats the wrong approach.) anyone know what the right way to go about this is (or if its even possible...) ?

sethladd
Nov 18th, 2005, 01:19 AM
Well, if the servlet is really simple, I would port it to an AbstractController, which is as simple as a servlet really.

I don't know if you can inject dependencies directly into servlets, as their lifecycles are outside the scope of Spring. I could be wrong.

You could, though, simply look up the dependency using WebApplicationContextUtils.

So, for the mapping, you can use either ServletForwardingController or ServletWrappingController.