0

I am trying to put Spring and SpringMVC into our really legacy project. The problem is that our project is really large and contains huge amount of proprietary request handling. I have to introduce it incrementally because the old handlers have to work with old infrastructure. Because of that I have to use the original servlet. There was no problem to change it to DispatcherServlet, the only problem that I have to solve is the fact, that I need to distinguish between class that is Controller and class, which has to be handled in old way.

I need to obtain class that the DispatcherServlet will dispatch this request to. Is it possible to somehow query SpringMVC to get bean which will serve as controller?

Thanks

Martin Macak
  • 3,507
  • 2
  • 30
  • 54

2 Answers2

0

I feel this thread should help you. Once you get the list of Controllers then you can check its @RequestMapping param with similar method to check its context path with the incoming request's context-path, to get the controller for a request.

Community
  • 1
  • 1
sanbhat
  • 17,522
  • 6
  • 48
  • 64
  • I have already found this comment but that's not what I am looking for. If I use this approach it would mean that I have to check all the mappings (evaluate relative paths etc), which means replicating some service that has been already implemented somewhere in SpringMVC. There has to be something in Spring that does that already. – Martin Macak Apr 29 '13 at 07:07
0

I have never had to do this in a large application, but the few times that I did migrate an existing servlets based application to spring MVC, this is how I did it:

  1. Map all existing requests to DispatcherServlet

  2. Create a controller that will handle any request url /**. In this controller, delegate request handling to existing server side components, with any luck this would mean one or more servlets. I would call this a Global Controller.

  3. At the end of this, you should have an application that has a proxy DispatcherServlet / controller that essentially uses your old code.

  4. Next, I would incrementally implement new controllers / methods for specific URLs that I want to service using Spring MVC. Since your request mapping urls for these would be specific, new controllers will be called instead of the Global Controller.

As you keep implementing new specific request mappings, controllers and controller methods, you reach a point where there are no or few requests handled by the Global Controller.

Hope this answers your question.

Akshay
  • 3,158
  • 24
  • 28