0

I’m upgrading a legacy Java Spring MVC application.

  • Current setup:

    • Java 1.8 (recently upgraded from Java 1.7)
    • Spring 3.2.18
    • Uses the old AbstractFormController, SimpleFormController, and XML-based config.
  • Goal: Upgrade to at least Java 10, preferably Java 17/18, and a newer Spring version (5.x or 6.x).

  • Problem: In newer Spring versions, AbstractFormController and other form controllers are removed or deprecated. Everything is now annotation-based (@Controller, @RequestMapping, etc.). For example, I currently have something like this:

public class BulkRequestController  extends SimpleFormController {

public ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command,BindException errors) throws Exception {
        ModelAndView mav = new ModelAndView();
        
        String operation = request.getParameter("hdnOperation");
        String mode = request.getParameter("mode");
        // My Code  
        return mav;
    }

protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception {
        final ModelAndView mav = new ModelAndView();
        String mid = request.getParameter("mid");
        
        if(CoreUtility.BULK_REQ_STRIKE.equalsIgnoreCase(mid)) {
            mav.addAllObjects(setDateValues());
            mav.setViewName(getBatchStrikeFormView());
        } else {
            throw new Exception("Un-implemented mid :" + mid);
        }
        
        return mav;
    }
 }

But in the newer Spring MVC, this whole controller pattern doesn’t exist anymore.

  • Question:

    1. What’s the correct way to migrate such controllers to annotation-based Spring MVC (@Controller, @PostMapping, etc.)?
    2. Are there tools or a standard migration guide for moving from Spring 3.2.x FormControllers to Spring 5/6 annotations?
    3. Any recommended step-by-step upgrade path (Spring 3 → 4 → 5 → 6) when also upgrading Java (to 10/17)?
  • Extra Notes:

    • The project is large, with many XML-based Spring beans and FormControllers.
    • I don’t want to rewrite everything at once; gradual migration advice is appreciated.
2
  • 2
    Small steps as upgrading Spring versions will eventually lead to supporting library upgrades. If you go from 3 to 6 including the required java upgrade, javax -> jakarta migration, things will break and you have no idea why (is it the version upgrade spring, new library requirement, jdk upgrade etc. etc.). Follow the Spring Framework migration guides between the different versions. The modification to your controllers could be as simple as remove the extends, add @Controller and annotate the methods with @GetMapping / @PostMapping depending on which method and use. Commented Sep 16 at 8:05
  • Simplest version of a starting point for the above suggestion is add @GetMapping to your showForm() method and @PostMapping to processFormSubmission(). You'll be able to make a lot of simplifications with other annotations as well now, but that should get you started. Commented Sep 19 at 21:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.