REST 给予 404

REST giving 404

我在一个运行良好的项目 (eclipse) 中使用 jersey 编写了一个 REST web 服务。现在我正在尝试将该 web 服务移动到一个已经存在的项目中,但它以 404 状态失败。 它正在工作的项目的 web.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.javatpoint.rest</param-value>
    </init-param>
    <init-param>
       <param-name>jersey.config.server.provider.classnames</param-name>
       <param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>
</web-app>

现在使用此配置并且 "jerseyhelloworldtest" 是我的 .war 文件的名称,我可以使用 URL http://localhost:8080/jerseyhelloworldtest/rest/files/name 访问网络服务 但是,当我将同一个 web 服务移动到另一个项目并使用该项目的 .war 文件名更改 jerseyhelloworldtest 时,它在那里不起作用。项目的web.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Softwarepartwebservice</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>/axis2-web/index.jsp</welcome-file>
 </welcome-file-list>
 <servlet>
   <display-name>Apache-Axis Servlet</display-name>
   <servlet-name>AxisServlet</servlet-name>
   <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
</servlet>
 <servlet-mapping>
   <servlet-name>AxisServlet</servlet-name>
   <url-pattern>/servlet/AxisServlet</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
   <servlet-name>AxisServlet</servlet-name>
   <url-pattern>*.jws</url-pattern>
 </servlet-mapping>
<servlet-mapping>
  <servlet-name>AxisServlet</servlet-name>
  <url-pattern>/services/*</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
     <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.javatpoint.rest</param-value>
     </init-param>
     <init-param>
         <param-name>jersey.config.server.provider.classnames</param-name>
         <param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>

<servlet>
  <display-name>Apache-Axis Admin Servlet Web Admin</display-name>
  <servlet-name>AxisAdminServlet</servlet-name>
  <servlet-class>org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
 <load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>AxisAdminServlet</servlet-name>
    <url-pattern>/axis2-admin/*</url-pattern>
 </servlet-mapping>
 <security-constraint>
    <web-resource-collection>
        <web-resource-name>Part Creator</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>manager</role-name>
    </auth-constraint>

    <user-data-constraint>
        <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
</login-config>
 </web-app>

现在我正在尝试使用 URL http://localhost:8080/Softwarepartwebservice/rest/files/name 访问相同的网络服务,但它给出了 404。 需要帮助。

抱歉,这是我犯的一个非常愚蠢的错误,我从来没有注意到。在更改项目时,我必须更新

中的包条目
  <init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>com.javatpoint.rest</param-value>
 </init-param>

到我的新包裹,其中放置了服务 class。 com.javatpoint.rest 是我更改为新项目的旧项目的包。改变它使它起作用。写在这里以防万一这可能会帮助面临同样问题的人。