簡體   English   中英

澤西網頁服務404錯誤

[英]jersey webservices 404 error

我知道有很多類似的問題都有很多答案。但是沒有一個實際上幫助我解決了這個問題。 這就是為什么我決定發布一個新問題的原因。因此,基本上我使用的是帶角度前端的運動衫。當我執行我的URL http:// localhost:8081 / hibernate-jersey-angularjs / rest / leave / list時 ,它顯示404錯誤“請求的資源不可用”。以下是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container, see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<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" version="2.5">
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Jersey Web Application</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.abc.rest</param-value>
    </init-param>
    <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>

和網絡服務:

package com.abc.rest;


import java.util.Iterator;
import java.util.List;


import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.abc.dao.AddLeaveDao;

import com.abc.dao.LeaveDao;

import com.abc.entity.LeaveBalance;
//import com.abc.entity.Love;
import com.abc.entity.LeaveDetails;

@Path("/leave")
public class LeaveWS {

    @GET
    @Path("list")
    @Produces({ "application/json" })
    public List<LeaveBalance> list() {
        List l= new LeaveDao().getAllLeaves();
        return l;
    }

    @POST
    @Path("create")
    @Consumes({ MediaType.APPLICATION_JSON})
    @Produces({ "application/json" })
    public String create(LeaveDetails ld) {

        new AddLeaveDao().addDetails(ld);
        System.out.println("Returned  here");
        return "{}";
    }




}

和項目結構:

在此處輸入圖片說明

請幫助我解決這個問題

在您的資源中,路徑映射應以“ /”為前綴

@Path("/list")
@Produces({ "application/json" })
public List<LeaveBalance> list() {
    List l= new LeaveDao().getAllLeaves();
    return l;
}

進行此更改后,如果您使用的是maven,請執行mvn clean install以更新您的資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM