在Spring中使用注释时出错

时间:2012-12-22 04:46:00

标签: java spring annotations

我是高级java和学习Spring框架的新手。我找到了一个教程

http://netbeans.org/kb/docs/web/quickstart-webapps-spring.html

在下面的代码中

package contoller;

import java.net.BindException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import service.HelloService;
/**
*
* @author Manish
*/
public class HelloController extends SimpleFormController {

public HelloController() {
setCommandClass(Name.class);
setCommandName("name");
setSuccessView("helloView");
setFormView("nameView");
}
 private HelloService helloService;
 public void setHelloService(HelloService helloService) {
 this.helloService = helloService;
  }

@Override          // Error Method does not override or implment a method of supertype
protected ModelAndView onSubmit(
        HttpServletRequest request,
        HttpServletResponse response,
        Object command,
        BindException errors) throws Exception {

    Name name = (Name) command;
    ModelAndView mv = new ModelAndView(getSuccessView());
    mv.addObject("helloMessage", helloService.sayHello(name.getValue()));
    return mv;
  }

如何解决此问题?

问候。

1 个答案:

答案 0 :(得分:1)

  

错误:方法不会覆盖或实现超类型方法

这与Spring无关。它在您的SimpleFormController课程中说没有方法onSubmit

将此方法添加到SimpleFormController课程中,问题就解决了。