0

我按照教程here

而且由于某种原因我无法运行该示例......在运行服务后输入 url http://localhost:8080/greeting/时出现 404 错误。

我正在使用 Intellji EE 14 和 TomEE 7。

这是我的代码:

Greeter.java:

package org.mybiz;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("greeting")
public class Greeter {
    @GET
    public String sayHi() {
        return "Hi!!";
   }
}

网页.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
</web-app>
4

1 回答 1

1

你能检查它是否部署在日志中(你应该有http://localhost:8080/greeting/

如果不是,它们可能是编译问题,如果是,并且您在访问 url 时遇到异常,则可能是您使用与定义的 mimetype 不匹配的 mimetype 访问它。

尝试添加@Consumes("text/plain")@Consumes("text/html")

于 2016-12-07T10:13:43.387 回答