首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么头"Accept: application/xml“在迁移到Java 11之后在Spring中不能工作?

为什么头"Accept: application/xml“在迁移到Java 11之后在Spring中不能工作?
EN

Stack Overflow用户
提问于 2020-02-27 08:42:21
回答 1查看 792关注 0票数 2

我想把Spring项目从JDK 8移到11。

控制器:

代码语言:javascript
复制
    @RequestMapping(value = "/{model}/columns", method = RequestMethod.GET, consumes = MediaType.ALL_VALUE, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE })
    public ResponseEntity<DataModel> getColumnsModel(@PathVariable String model) {
        LOGGER.info("getColumnsModel : model[{}]", model);
        DataModel dataModel = modelService.getColumns(model);
        return Optional.ofNullable(dataModel).map(result -> new ResponseEntity<>(result, HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NO_CONTENT));
    }

我的JSON卷(在JDK 8和JDK 11中可以):

代码语言:javascript
复制
curl -s --header "Accept: application/json" http://localhost:8084/noraui/api/hello/columns > target/actual_hello_columns.json

我的XML (在JDK 8中确定,但在JDK 11中不确定):

代码语言:javascript
复制
curl -s --header "Accept: application/xml" http://localhost:8084/noraui/api/hello/columns > target/actual_hello_columns.xml

在JDK 11中,结果是空的。

如何解决这个问题(我需要在JDK8和JDK11上使用我的代码)?

编辑:

我有一个错误:

代码语言:javascript
复制
Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-27 09:04:59

尝试使用更高版本的Jackson以获得XML支持。

pom.xml中添加此依赖项。

代码语言:javascript
复制
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.10.1</version>
</dependency>

spring-boot 2.1.6.RELEASE只调用jackson-dataformat-xml 2.9.9,如果您使用2.10.1,它就解决了这个问题。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60429282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档