2014-01-28 33 views
0

我正在開發我的第一個基於Spring的示例項目。以下是我的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" /> 

我嘗試做一個郵寄到以下網址,但它似乎從來沒有達到相應的控制器類:

網址: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錯誤,儘管一切似乎都已到位?

+0

請添加您的控制器代碼。另外,您的jar文件名是什麼?你在哪個服務器上運行?你如何構建你的應用程序(Maven?),你如何部署你的應用程序? – forhas

+0

增加了控制器代碼。我從eclipse運行它,並使用Tomcat 7.0。我沒有使用maven。我從eclipse編譯代碼。你能讓我知道你指的是哪個jar文件嗎? – user264953

+0

在tomcat上運行你的應用程序,你需要先構建它,然後你把你的 .war文件(這是構建工件),並將其部署到tomcat(你使用Eclipse的tomcat插件?)。 – forhas

回答

1

student前添加斜線:

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

此外,我希望自己的作品神器將TestProject.war,因爲這是你的路徑的PARTH。

+0

我在「學生」之前加了斜線並嘗試了 - 沒有工作。你能否讓我知道,我可以在哪裏看到這個jar文件,以便我可以檢查和確認。 – user264953

+0

這是一個maven項目嗎?你如何建立你的項目?如果您不確定您是否可以回答我的問題,請描述您爲了在本地tomcat上運行您的應用程序而做了什麼 – forhas

+0

爲什麼您認爲這會導致400? –