【问题标题】:Web service validation fails after run on Tomcat在 Tomcat 上运行后,Web 服务验证失败
【发布时间】: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>

【问题讨论】:

    标签: java tomcat jax-rs


    【解决方案1】:

    我无法从您提供的日志中做出正确的决定,但是当我快速阅读您提供的链接时,我认为您应该删除 web.xml 文件,因为作者还在cmets他没有使用web.xml

    【讨论】:

      【解决方案2】:

      问题是我使用的是 Jax-rs 规范,但我没有实现规范的引擎,正如 this 帖子中所报告的那样

      我将 Jersey 添加到项目库中,一切正常。

      【讨论】:

        猜你喜欢
        • 2020-01-11
        • 1970-01-01
        • 2011-07-07
        • 1970-01-01
        • 1970-01-01
        • 2023-01-16
        • 1970-01-01
        • 1970-01-01
        • 2016-09-23
        相关资源
        最近更新 更多