【发布时间】:2019-07-22 16:06:36
【问题描述】:
我是 Java 和 Java 中的 RESTful Web 服务的新手。我按照本教程开发了一个 Web 服务:https://www.theserverside.com/video/Step-by-step-RESTful-web-service-example-in-Java-using-Eclipse
在 Eclipse 中,当我在 Tomcat v9 (TomEE plume 8.0.0) 上运行该服务时,我收到以下错误(这对我没有任何意义):
原因:org.apache.openejb.config.ValidationFailedException:模块验证失败。 AppModule(name=restful-java) 在 org.apache.openejb.config.ReportValidationResults.deploy(ReportValidationResults.java:88) 在 org.apache.openejb.config.AppInfoBuilder.build(AppInfoBuilder.java:327) 在 org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:1036) 在 org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1286)
模块验证失败但没有写在哪里。有人可以帮我吗?
package com.palazzo.christian;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.json.JSONObject;
@Path("/")
public class FtoCService {
@GET
@Path("/convertftoc")
@Produces("application/json")
public Response convertFtoC() throws JSONException {
JSONObject jsonObject = new JSONObject();
Double fahrenheit = 98.24;
Double celsius;
celsius = (fahrenheit - 32) * 5 / 9;
jsonObject.put("F Value", fahrenheit);
jsonObject.put("C Value", celsius);
String result = "@Produces(\"application/json\") Output \n\nF to C Converter Output: \n\n" + jsonObject;
return Response.status(200).entity(result).build();
}
@GET
@Path("/convertftoc/{f}")
@Produces("application/json")
public Response convertFtoCfromInput(@PathParam("f") float f) throws JSONException {
JSONObject jsonObject = new JSONObject();
float celsius;
celsius = (f - 32) * 5 / 9;
jsonObject.put("F Value", f);
jsonObject.put("C Value", celsius);
String result = "@Produces(\"application/json\") Output \n\nF to C Converter Output: \n\n" + jsonObject;
return Response.status(200).entity(result).build();
}
}
这里是 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>restful-java</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
【问题讨论】: