【发布时间】:2017-01-11 08:52:02
【问题描述】:
我使用 undertow+resteasy+ajckson 开发 REST 服务,当我使用 IDEA 运行它时,一切正常,但是当我使用 gradle 或 maven 创建“fat-jar”时,我在 GET 查询期间出现错误:
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: 不能 为类型的响应对象查找 MessageBodyWriter 在 org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:67) 在 org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:448) 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:397) 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:200) 在 org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) 在 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) 在 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) 在 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();
}
【问题讨论】:
标签: java jackson resteasy undertow