Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 方法';邮政';不支持405_Java_Spring_Spring Mvc_Post - Fatal编程技术网

Java 方法';邮政';不支持405

Java 方法';邮政';不支持405,java,spring,spring-mvc,post,Java,Spring,Spring Mvc,Post,我有一个上传文件的POST方法。上传文件时,请在我的标题上传递令牌 private RessourceMetadata doSave(Ressource ressource) throws IOException, FileNotFoundException { String tempFilePath = writeDocumentToTempFile(ressource); MultiValueMap<String, Object> parts =

我有一个上传文件的
POST
方法。上传文件时,请在我的
标题上传递
令牌

private RessourceMetadata doSave(Ressource ressource) throws IOException, FileNotFoundException {
        String tempFilePath = writeDocumentToTempFile(ressource);
        MultiValueMap<String, Object> parts = createMultipartFileParam(tempFilePath);
        RessourceMetadata ressourceMetadata = getRestTemplate().postForObject(
                getServiceUrl()
                        + "/uploadFileProperties?group={group}&projectId={projectId}&version={version}&env={env}",
                parts, RessourceMetadata.class, ressource.getGroup(), ressource.getId(), ressource.getVersion(),
                ressource.getEnv());
        return ressourceMetadata;
    }
我的代码有什么问题

发布方法:

@RequestMapping(value = "/uploadFileProperties", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ApiImplicitParams({
        @ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header") })
public @ResponseBody RessourceMetadata uploadProperties(
        @ApiParam(name = "file", value = "fichier properties à uploader", defaultValue = "", required = true) @RequestParam("file") MultipartFile file,
        @ApiParam(name = "group", value = "groupe projet", defaultValue = "", required = true) @RequestParam("group") String group,
        @ApiParam(name = "projectId", value = "id projet (francevisas, diplomatie...)", defaultValue = "", required = true) @RequestParam("projectId") String projectId,
        @ApiParam(name = "version", value = "version du projet", defaultValue = "", required = true) @RequestParam("version") String version,
        @ApiParam(name = "env", value = "environnement (dev, prod, formation...)", defaultValue = "", required = true) @RequestParam("env") String env) {

    try {
        Ressource ressource = new Ressource(file.getBytes(), group, projectId, version, env,
                PropertiesFileUtils.getPropertiesFilename());
        getRessourceService().save(ressource);
        return ressource.getMetadata();
    } catch (RuntimeException e) {
        log.error("Error while uploading.", e);
        throw e;
    } catch (Exception e) {
        log.error("Error while uploading.", e);
        throw new RuntimeException(e);
    }
}

在doSave()方法中,调用getServiceUrl()方法并向其添加路径。getServiceUrl()必须返回其他域。要检查它,请在doSave()方法中进入调试模式,并查看getService方法是否为您提供了正确的值。此外,请使用getServiceUrl从Postman提供给您的域来尝试您的POST请求。

这似乎非常清楚。该URL不接受帖子。你的问题是什么?@shmosel为什么我不能发布?我不知道spring的异常格式,但我想如果看到
o.s.w.s.PageNotFound
的话,你会被重定向到“PageNotFound”页面,因为URL不正确,页面不支持
发布
请发布
@Controller
方法。它必须有
method=RequestMethod.POST
@JackFlamp我有
POST
方法
o.s.w.s.PageNotFound - Request method 'POST' not supported
 2017-Jun-15 09:50:31.852 ERROR [main] f.g.d.d.w.c.ServiceClient - Error while uploading file
 org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed
@RequestMapping(value = "/uploadFileProperties", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ApiImplicitParams({
        @ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header") })
public @ResponseBody RessourceMetadata uploadProperties(
        @ApiParam(name = "file", value = "fichier properties à uploader", defaultValue = "", required = true) @RequestParam("file") MultipartFile file,
        @ApiParam(name = "group", value = "groupe projet", defaultValue = "", required = true) @RequestParam("group") String group,
        @ApiParam(name = "projectId", value = "id projet (francevisas, diplomatie...)", defaultValue = "", required = true) @RequestParam("projectId") String projectId,
        @ApiParam(name = "version", value = "version du projet", defaultValue = "", required = true) @RequestParam("version") String version,
        @ApiParam(name = "env", value = "environnement (dev, prod, formation...)", defaultValue = "", required = true) @RequestParam("env") String env) {

    try {
        Ressource ressource = new Ressource(file.getBytes(), group, projectId, version, env,
                PropertiesFileUtils.getPropertiesFilename());
        getRessourceService().save(ressource);
        return ressource.getMetadata();
    } catch (RuntimeException e) {
        log.error("Error while uploading.", e);
        throw e;
    } catch (Exception e) {
        log.error("Error while uploading.", e);
        throw new RuntimeException(e);
    }
}