org.jboss.resteasy.resteasy_jaxrs.i18n; org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure報錯

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();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章