当前位置: 首页 > 知识库问答 >
问题:

获取组织。springframework。网状物客户HttpClientErrorException:415 Spring Rest Web服务不支持的媒体类型

能旭
2023-03-14

获取Spring Rest控制器Web服务的以下异常:-

org.springframework.web.client.HttpClientError异常: 415org.springframework.web.client.不支持的媒体类型默认响应错误andler.java:91org.springframework.web.client.的错误(默认响应错误andler.java:91)RESTTemplate.handle响应(RESTTemplate.java:667)

代码:

public class PaymentProcessController {

@RequestMapping(value = "/payment_failure", method = RequestMethod.POST)


    public ModelAndView savePayFailure(HttpServletRequest request, HttpServletResponse response, HttpSession session)
{
        RestTemplate restTemplate = new RestTemplate();
       Invoice invoice = restTemplate.getForObject(
                    "http://localhost:8080/rooftop/invoice/findByProperty/TRANASACTION_NO/" + tx
nid, Invoice.class);


}

REST客户端在InvoiceRestController中编写如下:

InvoiceRestController:

  @RestController @RequestMapping(value = "/invoice/") 

public class
            InvoiceRestController {     @RequestMapping(value =
            "/findByProperty/{property}/{value}", method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE, consumes =
            MediaType.APPLICATION_JSON_VALUE)

  public ResponseEntity<Invoice> findByProperty(@PathVariable String property, @PathVariable String value) throws Exception {

        }

共有1个答案

江宏放
2023-03-14

这个问题在你的设置中非常局部,所以我想不能提供一个普遍的答案。只有调试问题的步骤。

1.首先确保Http消息转换器已就位,即类路径中包含类似jackson的库

此库自动包含在Spring Boot中。

如果不使用任何框架,您可能需要做这样的事情

2.其次,当您从savePayFailure进行rest调用时,请确保设置了

您的RESTAPI使用的内容非常清楚

如何在SpringRESTTemplate请求上设置“Accept:”头?

HTTP获取使用RestTemboard的头

将我的自定义http头添加到Spring RestTemplate请求/扩展RestTemplate

按该顺序尝试两个步骤

 类似资料: