2017-02-27 90 views
1

我正在爲我的web服務編寫一個新的API。我已經嘗試過所有其他與此相關的計算器鏈接。但問題依然存在。不支持請求方法'POST'。 500內部服務器錯誤春季啓動

的問題是: 當我嘗試使用打我的春天啓動的應用程序:

curl -v -XPOST http://localhost:9081/postpayment/v1/invoice/djhbjsd/send 

我得到如下回應:

Trying ::1... 
Connected to localhost (::1) port 9081 (#0) 
POST /postpayment/v1/invoice/djhbjsd/send HTTP/1.1 
Host: localhost:9081 
User-Agent: curl/7.43.0 
Accept: */* 

HTTP/1.1 500 Internal Server Error 
Server: Apache-Coyote/1.1 
Content-Type: application/json;charset=UTF-8 
Transfer-Encoding: chunked 
Date: Mon, 27 Feb 2017 06:21:43 GMT 
Connection: close 

Closing connection 0 
{"timestamp":1488176503569,"status":500,"error":"Internal Server Error","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/postpayment/v1/invoice/djhbjsd/send"} 

我的控制器是:

@RestController 
public class PostPaymentApiController { 


    @ResponseBody 
    @RequestMapping(value = "/postpayment/v1/invoice/{invoiceGUID}/send", method = RequestMethod.POST) 
    public ResponseEntity<String> sendPaymentConfirmation(
     @PathVariable("invoiceGUID") String invoiceGUID) throws Exception { 

     try { 
      //logic 

     } catch (Exception e) { 

      LOGGER.error(invoiceGUID+" Error in sending payment confirmation",e); 
      return new ResponseEntity<String>(invoiceGUID+" "+e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 
     } 

     return new ResponseEntity<String>(invoiceGUID+" payment confirmation sent successfully",HttpStatus.OK); 
    } 

} 

日誌中的錯誤:

: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request method 'POST' not supported] with root cause 
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported 
at org.springframework.web.servlet.support.WebContentGenerator.checkRequest(WebContentGenerator.java:301) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:229) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcChildContextConfiguration$CompositeHandlerAdapter.handle(EndpointWebMvcChildContextConfiguration.java:266) ~[spring-boot-actuator-1.3.2.RELEASE.jar:1.3.2.RELEASE] 
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE] 

還有一件事。我正在對管理端口做出以下響應。當我打的服務器端口上,我得到404.My application.yml包含:

server.port: 9080 
    management.port: 9081 
+0

爲什麼您將@Configuration添加到RestController中? –

+0

'@ RestController'中的''@ ResponseBody''是多餘的btw –

+0

從控制器中刪除@Configuration。 – abhishekgarg

回答

0

你休息控制器包括@Configuration和處理方法包括哪些@ResponseBody沒有必要@RestController所以去除@Configuration和@來自您的控制器的ResponseBody

+0

已試過。不工作。 – abhishekgarg

+0

什麼是你的項目名稱,或者你可以上傳你的項目的文件夾結構 – shree

+0

這個回購是不公開的。你不能看到repo.btw項目名稱是「postpayment」 – abhishekgarg

相關問題