org.springframework.web.HttpMediaTypeNotSupportedException: 不支持内容类型 'application/xml;charset=UTF-8' [英] org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/xml;charset=UTF-8' not supported

查看:44
本文介绍了org.springframework.web.HttpMediaTypeNotSupportedException: 不支持内容类型 'application/xml;charset=UTF-8'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调用休息服务时遇到异常.

I am getting below exception when I am calling rest service.

org.springframework.web.HttpMediaTypeNotSupportedException:内容类型 'application/xml;charset=UTF-8' 不支持在 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:152)[spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]在 org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:181)[spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]在

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/xml;charset=UTF-8' not supported at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:152) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:181) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE] at

代码

    //    This method calls the rest service


        @Override
        public TransactionSearchResults callSearchTransactions(TransactionSearchCriteria criteria, int page, int size) {

        HttpEntity<TransactionSearchCriteria> requestEntity = new HttpEntity<TransactionSearchCriteria>(criteria, getCommonHeaders(new HttpHeaders()));

        Map<String, Integer> params = new HashMap<String, Integer>();
        params.put("size", size);
        params.put("page", page);

        return restTemplate.exchange(urlBase + "/transaction?size={size}&page={page}", HttpMethod.POST, requestEntity, TransactionSearchResults.class, params).getBody();

        }

    // Api which caters to rest call

        @Controller
        @RequestMapping("/transaction")
        public class TransactionStatusController extends BaseController { ... }

    //Controller method for rest call 
        @ResponseBody
        @RequestMapping(produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST , consumes = MediaType.APPLICATION_JSON_VALUE)
            public com.rest.TransactionSearchResults searchTransactions(@RequestParam(value = "page", required = false) Integer page,
// Using request Param to retireve criteria                         
@RequestParam(value = "size", required = false) Integer size, @Valid     @RequestBody com.rest.TransactionSearchCriteria criteria) {
// This gets relevant results and return it to rest call
    return convert(transactionService.search(convert(criteria), page, size));

}

推荐答案

问题已解决.下面给出的 pom 条目与 jackson 核心库冲突.刚刚删除它,一切正常.

The issue has been resolved. The pom entry given below which was conflicting with jackson core libraries. Just removed it and it all worked fine.

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.4.3</version>
</dependency>

这篇关于org.springframework.web.HttpMediaTypeNotSupportedException: 不支持内容类型 'application/xml;charset=UTF-8'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆