使用JSON正文返回的REST服务的POST操作
org.jboss.resteasy.spi.UnsupportedMediaTypeException
:不能消耗内容类型异常
两者@Consumes(MediaType.APPLICATION_JSON)并@Consumes("application/json")返回相同的异常.
我尝试使用Postman API客户端调用该服务.

@RolesAllowed("admin")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/auth")
public Response login(UserCl usr){
if(usr.getUsername().compareTo("user") == 0 &&
usr.getPassword().compareTo("pass") == 0){
return Response.status(200).build();
}
else{
return Response.status(401).build();
}
}
12:44:07,322 WARN [org.jboss.resteasy.core.SynchronousDispatcher] (http-localhost-127.0.0.1-8080-1) Failed executing POST user-service/auth: org.jboss.resteasy.spi.UnsupportedMediaTypeException: Cannot consume content type
at org.jboss.resteasy.core.registry.Segment.match(Segment.java:117) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.registry.SimpleSegment.matchSimple(SimpleSegment.java:33) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.registry.RootSegment.matchChildren(RootSegment.java:327) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.registry.SimpleSegment.matchSimple(SimpleSegment.java:44) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.registry.RootSegment.matchChildren(RootSegment.java:327) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.registry.RootSegment.matchRoot(RootSegment.java:374) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.registry.RootSegment.matchRoot(RootSegment.java:367) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:307) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:173) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:118) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:]
at …Run Code Online (Sandbox Code Playgroud) 我正在使用JBoss Application Server进行部署的Web项目中。启动服务器后,我收到以下消息。
应用程序服务器可能已在主机localhost上运行
Web Poller在URL http:// localhost:8080上找到了正在运行的服务器
我netstat在使用port的进程上的命令上找不到任何条目8080。
还尝试了此问题中提到的解决方案。