cxf maven 依赖 No message body writer foud.. contenttype:application/json

最近使用cxf发布rest服务时遇到了如题的异常,最后发现是缺少依赖的问题.ps:我并没有使用spring

cxf基本运行需要如下依赖

 1         <dependency>
 2             <groupId>org.apache.cxf</groupId>
 3             <artifactId>cxf-core</artifactId>
 4             <version>${cxf.version}</version>
 5         </dependency>
 6           <dependency>
 7             <groupId>org.apache.cxf</groupId>
 8             <artifactId>cxf-rt-frontend-jaxws</artifactId>
 9             <version>${cxf.version}</version>
10         </dependency>
11         <dependency>
12             <groupId>org.apache.cxf</groupId>
13             <artifactId>cxf-rt-transports-http</artifactId>
14             <version>${cxf.version}</version>
15         </dependency>
16         <dependency>
17             <groupId>org.apache.cxf</groupId>
18             <artifactId>cxf-rt-transports-http-jetty</artifactId>
19             <version>${cxf.version}</version>
20         </dependency>

如果想要发布rest风格的服务,需要添加如下依赖(看各人需要,有的可能需要添加rs-api的依赖)

 1         <!-- rest风格支持 -->
 2         <dependency>
 3             <groupId>org.apache.cxf</groupId>
 4             <artifactId>cxf-rt-frontend-jaxrs</artifactId>
 5             <version>${cxf.version}</version>
 6         </dependency>
 7         <dependency>
 8             <groupId>org.apache.cxf</groupId>
 9             <artifactId>cxf-rt-rs-extension-providers</artifactId>
10             <version>${cxf.version}</version>
11         </dependency>

这样就可以发布rest风格的服务了,不过这样有个问题,只能使用xml格式的数据,如果使用下面的注解,即添加json格式的返回数据访问时会报如题的no message body writer的异常

@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})

所以需要添加如下依赖

1         <!-- json支持 -->
2         <dependency>
3             <groupId>org.codehaus.jettison</groupId>
4             <artifactId>jettison</artifactId>
5             <version>${jettison.version}</version>
6         </dependency>

 

总结:出现no message body writer时先检查pojo上是否添加了jaxb的必要标记----@XmlRootElement,其次检查是否缺少依赖关系

 

转载于:https://www.cnblogs.com/tele-share/p/9371084.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值