gpt4 book ai didi

java - org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure : Could not find MessageBodyWriter for response object of type

转载 作者:太空宇宙 更新时间:2023-11-04 12:16:47 25 4
gpt4 key购买 nike

我使用 undertow+resteasy+ajckson 开发 REST-service,当我使用 IDEA 运行它时,一切正常,但是当我使用 gradle 或 maven 创建“fat-jar”时,我在 GET 查询期间收到错误:

org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:67) at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:448) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:397) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:200) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

我可以使用 gradle build 创建 jar,不会出现错误,并在 IDEA 中调试我的服务。

我的gradle文件:

apply plugin: 'application'
apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

mainClassName = 'example.json.RestServer'

jar {
manifest {
attributes 'Implementation-Title': 'Rest-server',
'Implementation-Version': '0.1',
'Main-Class': 'example.json.RestServer'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}

repositories {
jcenter()
}

dependencies {
compile 'io.undertow:undertow-core:1.4.0.Final'
compile 'io.undertow:undertow-servlet:1.4.0.Final'

compile 'org.jboss.resteasy:jaxrs-api:3.0.12.Final'
compile 'org.jboss.resteasy:resteasy-undertow:3.0.12.Final'
compile 'org.jboss.resteasy:resteasy-jackson-provider:3.0.12.Final'

testCompile 'junit:junit:4.12'
}

我的来源:

@Path("calculator")
public class Calculator {
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Response squareRoot(@QueryParam("input") double input){
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return Response.status(200).entity(result).build();
}

最佳答案

尝试像下面这样更改您的最后一个代码 spinet,因为匿名 GenericEntity 子类需要为编写者提供正确的类型信息(否则会被编译器删除)。

@Path("calculator")
public class Calculator {
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Response squareRoot(@QueryParam("input") double input){
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return Response.ok(
new GenericEntity<Result >(result)
)
}

更多解释在这里JAX-RS NoMessageBodyWriterFoundFailure

关于java - org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure : Could not find MessageBodyWriter for response object of type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39305944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com