当前位置: 首页 > 工具软件 > RESTEasy > 使用案例 >

org.jboss.resteasy.resteasy_jaxrs.i18n; org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure报错

顾永福
2023-12-01

resteasy和springboot集成暴露rest接口请求报错

2020-02-24 10:45:55.358 ERROR 11032 --- [-BIZ-8341-10-T1] org.jboss.resteasy.resteasy_jaxrs.i18n   : RESTEASY002005: Failed executing GET /get/students

org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: text/html;charset=UTF-8
	at org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$2(ServerResponseWriter.java:105) ~[resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.interception.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:398) ~[resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:206) ~[resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:82) ~[resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:56) ~[resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:528) [resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:459) [resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at com.alipay.sofa.rpc.server.rest.SofaSynchronousDispatcher.invoke(SofaSynchronousDispatcher.java:49) [sofa-rpc-all-5.6.4.jar:5.6.4]
	at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229) [resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135) [resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:355) ~[resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138) [resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215) [resteasy-jaxrs-3.6.3.Final.jar:3.6.3.Final]
	at org.jboss.resteasy.plugins.server.netty.RequestDispatcher.service(RequestDispatcher.java:83) ~[resteasy-netty4-3.6.3.Final.jar:3.6.3.Final]
	at com.alipay.sofa.rpc.server.rest.SofaRestRequestHandler.channelRead0(SofaRestRequestHandler.java:102) ~[sofa-rpc-all-5.6.4.jar:5.6.4]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:56) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:365) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-all-4.1.43.Final.jar:4.1.43.Final]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_231]

接口定义如下:

@Path("get")
public interface StudentApi {

    @GET
    @Path("students")
    List<StudentDetailDto> getStudentList();
}

经过排查,是由于没有指定返回体类型导致的,新增注解指定返回媒体类型,接口顺利返回

@Path("get")
@Produces({MediaType.APPLICATION_JSON})
public interface StudentApi {

    @GET
    @Path("students")
    List<StudentDetailDto> getStudentList();
}
 类似资料: