泽西岛的Web服务仅返回404

时间:2021-08-03 19:33:42

I have read some questions here about this problem and strongly believe that its not the case here. So I have a class like this :

我在这里已经阅读了一些关于这个问题的问题,并坚信在这里并非如此。所以我有一个这样的课:

package Rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/hello")
public class HelloWorldService {

    @GET
    @Path("/{param}")
    public Response getMsg(@PathParam("param") String msg) {

        String output = "Jersey say : " + msg;

        return Response.status(200).entity(output).build();

    }

}

And my web.xml:

我的web.xml:

<web-app id="WebApp_ID" version="2.4"
  xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Restful Web Application</display-name>

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
            org.glassfish.jersey.servlet.ServletContainer
        </servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>Rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

And my stack trace, which shows no Exception :

我的堆栈跟踪,没有显示异常:

Mai 09, 2017 10:48:25 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:RestTest' did not find a matching property.
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version:        Apache Tomcat/9.0.0.M20
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built:          Apr 12 2017 19:27:10 UTC
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number:         9.0.0.0
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name:               Windows 10
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version:            10.0
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture:          amd64
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home:             C:\Program Files\Java\jre1.8.0_121
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version:           1.8.0_121-b13
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor:            Oracle Corporation
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE:         C:\Users\phamt\OneDrive\MyLittleProject\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Mai 09, 2017 10:48:25 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 9.0
Mai 09, 2017 10:48:26 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=C:\Users\phamt\OneDrive\MyLittleProject\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Mai 09, 2017 10:48:26 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
Mai 09, 2017 10:48:26 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=C:\Users\phamt\OneDrive\MyLittleProject\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Mai 09, 2017 10:48:26 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 9.0\endorsed
Mai 09, 2017 10:48:26 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=UTF-8
Mai 09, 2017 10:48:26 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_121\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/bin/server;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/bin;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/lib/amd64;C:\Program Files\Java\jdk1.8.0_121\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files (x86)\sbt\bin;C:\Users\phamt\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Java\jre1.8.0_121\bin;;C:\Users\phamt\eclipse\java-neon\eclipse;;.]
Mai 09, 2017 10:48:26 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Mai 09, 2017 10:48:27 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Mai 09, 2017 10:48:27 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Mai 09, 2017 10:48:27 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Mai 09, 2017 10:48:27 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 2620 ms
Mai 09, 2017 10:48:27 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service [Catalina]
Mai 09, 2017 10:48:27 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/9.0.0.M20
Mai 09, 2017 10:48:30 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mai 09, 2017 10:48:34 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
Mai 09, 2017 10:48:34 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
Mai 09, 2017 10:48:34 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 7036 ms

I used Jersey 2.xx with Tomcat v9.0.

我使用Jersey 2.xx和Tomcat v9.0。

I tried some URLs like :

我试过一些像以下网址:

http://localhost:8080/RestTest/rest/hello/Tuan

http://localhost:8080/RestTest/rest/hello/

http://localhost:8080/RestTest/Rest/hello/Tuan

Which always show 404 Not found.

其中总是显示404未找到。

Any idea why?

知道为什么吗?

1 个解决方案

#1


2  

As @Libin said :

正如@Libin所说:

@Path("/{param}") should be @Path("{param}")

@Path(“/ {param}”)应该是@Path(“{param}”)

Solved!

#1


2  

As @Libin said :

正如@Libin所说:

@Path("/{param}") should be @Path("{param}")

@Path(“/ {param}”)应该是@Path(“{param}”)

Solved!