Jee6 Basic Rest服务返回404

时间:2014-08-16 17:26:44

标签: rest java-ee

我目前正在从Spring Framework切换到JEE6并且PoC测试了一些功能。其中一个是休息服务。我很确定我使用了休息注释来遵循JEE6教程,并且还交叉检查了JEE5示例以获取其他web服务。但是,我的示例确实返回404消息。一个正常的@WebServlet控制器运行正常,所以我没有任何内部/部署相关的错误。 Log-file / Stacktrace也是空的。

如果你能给我一些建议,那会很棒。谢谢!

Ĵ


控制器类

package guest;

import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;

// The Java class will be hosted at the URI path "/helloworld"
@Stateless
@Path("/helloWorld")
public class GuestRest {

    // The Java method will process HTTP GET requests
    @Path("test")
    @GET
    public String getClichedMessage() {
        // Return some cliched textual content
        return "<html><body><h1>Hello World</h1></body></html>";
    }
}

glassfish-web.xml

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <context-root>/Guestbook</context-root>

</glassfish-web-app>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

1 个答案:

答案 0 :(得分:0)

尝试更改您的web.xml(3.0版本和不同的REST初始化):

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>JAXRSSample</display-name>
    <servlet>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
    </servlet>

    <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>