restcontroller post方法405方法不允许

时间:2018-06-04 10:00:37

标签: java spring spring-boot

我有一个带有post方法的restcontroller以及下面的url和json请求。 http://server/member/sc/v1/limited-liability/medicare

package com.dckr.microsvc.medicaredtls.controller;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;


@RestController
public class UpdMedicareDtlsController {

    private static final Logger logger = LoggerFactory.getLogger(UpdMedicareDtlsController.class);

    @Autowired
    private UpdMedicareLLRecService updMedicareLLRecService;

    @Autowired
    ExceptionObjFactory expObjFactory;


    @RequestMapping(value = UpdMedicareLLConstants.UPD_MEDICARE_LL_URL, method = RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public InlineResponse200 updateMedicareLLRec(@RequestBody MedicareRequest updateMedicareRequest, 
            @RequestHeader(value=UpdMedicareLLConstants.META_TRANSID) String metatransid)
            throws Exception {

        long startTime = System.currentTimeMillis();
        logger.info("Entering UpdMedicareDtlsController -- updateMedicareLLRec(@Request MedicareRequest updateMedicareReq)");

        InlineResponse200 response = null;
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();


        logger.info( updateMedicareRequest.toString());

        if(null!=updateMedicareRequest)
        if ((null!=updateMedicareRequest.getMbruid()&&StringUtils.hasText(updateMedicareRequest.getMbruid()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getPrime()
        &&StringUtils.hasText(updateMedicareRequest.getMedicare().getPrime()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getQualifiedReason()
                &&StringUtils.hasText(updateMedicareRequest.getMedicare().getQualifiedReason()))
        &&(null!=updateMedicareRequest.getLlSeqNum()&&StringUtils.hasText(updateMedicareRequest.getLlSeqNum()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getPartA()
                &&null!=updateMedicareRequest.getMedicare().getPartA().getPrimary()
                &&StringUtils.hasText(updateMedicareRequest.getMedicare().getPartA().getPrimary()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getPartB()
        &&null!=updateMedicareRequest.getMedicare().getPartB().getPrimary()
        &&StringUtils.hasText(updateMedicareRequest.getMedicare().getPartB().getPrimary()))) {
            response = updMedicareLLRecService.updateLLRecord(updateMedicareRequest, metatransid);
        } else {
            throw expObjFactory.createNewAppexception("3002", UpdMedicareLLConstants.MISSING_MANDATORY_DATA);
        }
        else {
            throw expObjFactory.createNewAppexception("3002", UpdMedicareLLConstants.MISSING_MANDATORY_DATA);
        }

        stopWatch.stop();

        logger.info("Exiting UpdMedicareDtlsController -- updateMedicareLLRec() time taken : "+ stopWatch.getTotalTimeMillis());
        return response;

    }
}

在使用post方法和json请求在本地触发请求时,获得正确的响应。但是在docker中作为spring boot app运行会抛出异常,因为方法不允许。最初我将此docker服务部署为put方法。现在我已经转移到post方法。如果我改变我的方法回到put方法。这工作正常。

响应: 日期:2018年6月4日星期一09:30:16 GMT 内容长度0

status#HTTP / 1.1 405 Method Not Allowed

允许POST 连接保持活着 X-Application-Context scupdatemedicaredtls:坐下 服务器nginx / 1.13.10

任何人请建议适当的回应。

1 个答案:

答案 0 :(得分:0)

未使用与路径和参数对应的post方法部署运行时jar。仔细检查您的部署。