I would like to convert this SimpleFormController to use annotation support introduced in Spring MVC 2.5
Java
public class PriceIncreaseFormController extends SimpleFormController { ProductManager productManager = new ProductManager(); @Override public ModelAndView onSubmit(Object command) throws ServletException { int increase = ((PriceIncrease) command).getPercentage(); productManager.increasePrice(increase); return new ModelAndView(new RedirectView(getSuccessView())); } @Override protected Object formBackingObject(HttpServletRequest request) throws ServletException { PriceIncrease priceIncrease = new PriceIncrease(); priceIncrease.setPercentage(20); return priceIncrease; } }
Spring Configuration
<context:annotation-config/> <context:component-scan base-package="springapp.web"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <bean name="/priceincrease.htm" class="springapp.web.PriceIncreaseFormController"> <property name="sessionForm" value="true"/> <property name="commandName" value="priceIncrease"/> <property name="commandClass" value="springapp.service.PriceIncrease"/> <property name="validator"> <bean class="springapp.service.PriceIncreaseValidator"/> </property> <property name="formView" value="priceincrease"/> <property name="successView" value="hello.htm"/> <property name="productManager" ref="productManager"/> </bean>
Basically, I would like to replace the whole XML configuration for /priceincrease.htm bean with annotations in the Java class. Is this possible, and if so, what are the relevant annotations I should use?
Thanks Don
Dónal source share