Spring:发布请求未到达控制器类

时间:2014-01-28 12:32:11

标签: java spring java-ee spring-mvc

我正在开发我的第一个基于弹簧的项目。以下是我的dispatcher-servlet.xml的摘录。

<mvc:view-controller path="" view-name="test" />
<!-- location to scan for controllers -->
<context:component-scan base-package="com.test.demo.student.controller" />

我尝试对以下网址发帖,但它似乎永远不会到达相应的控制器类:

url:http://localhost:8080/TestProject/student/retrieveDetails

@Controller
@RequestMapping("student")
public class StudentController {

private final Logger logger = Logger.getLogger(StudentController.class);

@Autowired
public StudentService studentService;

public void setStudentService(StudentService studentService) {
    this.studentService = studentService;
}


 @RequestMapping(value = "/retrieveDetails", method = RequestMethod.POST)
public @ResponseBody String retrieveDetails(@RequestBody RetrieveStudentRequestBo retrieveStudentRequestBo,HttpServletRequest req,HttpServletResponse res) {

    logger.info("Entering StudentController.retrieveDetails()" );

发布帖子{"testID":"1"}

ERROR [400]
Bad Request 

是回应。

为什么我会收到400错误,但似乎所有内容都已到位?

1 个答案:

答案 0 :(得分:1)

请在student之前添加斜杠:

@Controller
@RequestMapping("/student")
public class StudentController {
...
}

此外,我希望您的构建工件为TestProject.war,因为这是您路径的一部分。