Search code examples
springframeworksupgrade

Spring framework upgrade - Modifying the code


Trying to upgrade a springframe work project from very old version to latest version 5.3. After replacing old jar files with new I am seeing compile errors. Below is the sample code. Appreciate your help to update the below code using the latest framework.

Errors @ 1. SimpleFormContrller - Not found 2. retun new RedirectView(getSuccessView() - Notfound.

public class RangeFormController extends SimpleFormController {

   Protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {

    return new ModelAndView(new RedirectView(getSuccessView()));
  }
}

 Spring-Context.xml
<bean id="RangeFormController " 
 class="org.test.controller.RangeFormController ">
  <property name="sessionForm"><value>true</value></property>
  <property name="commandName"><value>fileUpload</value></property>      
  <property name="formView"><value>FileUpload</value></property>
  <property name="successView"><value>upload.html</value></property>      
</bean>

Solution

  • SimpleFormController was deprecated in 3.0. You should use @Controller instead as follows:

    @Controller
    public class RangeFormController {
    
    }
    

    As a consequence getSuccessView() will also not be available. Simply use a String as a parameter to RedirectView. Reference documentation: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/view/RedirectView.html#RedirectView-java.lang.String-.