java – 405 Spring不允许的方法

我对HTTP端点进行了以下测试:

public static final String DATA_PARAMETER = "data";

public static final String ID_PARAMETER = "id";

public static final String VIDEO_SVC_PATH = "/video";

public static final String VIDEO_DATA_PATH = VIDEO_SVC_PATH + "/{id}/data";

@Multipart
@POST(VIDEO_DATA_PATH)
public VideoStatus setVideoData(@Path(ID_PARAMETER) long id, @Part(DATA_PARAMETER) TypedFile videoData);

@Test
public void testAddVideoData() throws Exception {
    Video received = videoSvc.addVideo(video);
    VideoStatus status = videoSvc.setVideoData(received.getId(),
            new TypedFile(received.getContentType(), testVideoData));
    assertEquals(VideoState.READY, status.getState());

    Response response = videoSvc.getData(received.getId());
    assertEquals(200, response.getStatus());

    InputStream videoData = response.getBody().in();
    byte[] originalFile = IOUtils.toByteArray(new FileInputStream(testVideoData));
    byte[] retrievedFile = IOUtils.toByteArray(videoData);
    assertTrue(Arrays.equals(originalFile, retrievedFile));
}

我正在尝试使用Swing中定义的以下端点来实现此测试定义的要求:

@RequestMapping(method = RequestMethod.POST, value = "/video/{id}/data")
public void postVideoData(@PathVariable("id") long videoId,
        @RequestParam("data") MultipartFile videoData) throws IOException {
    if (videoId <= 0 || videoId > videos.size()) {
        throw new ResourceNotFoundException("Invalid id: " + videoId);
    }

    Video video = videos.get((int)videoId - 1);
    InputStream in = videoData.getInputStream();
    manager.saveVideoData(video, in);
}

问题是我得到“405 Method Not Allowed”错误.我做错了什么,以至于我的POST方法无法识别?

解决方法:

问题是客户端接口需要从服务器返回的VideoStatus对象.我声明服务器端的方法返回void.

上一篇:【Go语言系列】1.4、GO语言简介:第一个Go语言程序


下一篇:java – 我应该使用改造休息客户端,因为我已经在我的webapp中使用了Spring框架