spring 找不到url Observer的请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8532309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:49:08  来源:igfitidea点击:

Can't find the request for url Observer

springrestmavencxf

提问by Ananth Duari

I am working with sample REST service with Apache CXF, But somehow I am not able to call the service. My implementation class is,

我正在使用 Apache CXF 使用示例 REST 服务,但不知何故我无法调用该服务。我的实现类是,

package com.ananth.lab.cfxrest.service;

import com.ananth.lab.cfxrest.vo.Address;
import com.ananth.lab.cfxrest.vo.Employee;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import javax.ws.rs.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


@Path("/cservice")
@Produces("application/xml")
public class EmployeeService {

    @GET
    @Path("/emp")

    public Employee getEmployee() {

        Address address1 = new Address();
        address1.setCity("Chennai");
        address1.setZip(63);
        List<Address> list = new ArrayList<Address>();
        Address address2 = new Address();
        address2.setCity("Bangalore");
        address2.setZip(49);
        list.add(address1);
        list.add(address2);
        Employee emp = new Employee();
        emp.setAddress(list);
        emp.setEmployeeId("001");
        emp.setEmployeeName("Ananth");

        return emp;
    }
}

My web.xml file is,

我的 web.xml 文件是,

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Hello world REST service with apache cxf</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/beans.xml,WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <display-name>CXF Servlet</display-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

I deployed in Tomcat and the context path is "Lab". So I am trying to access the service like:

我部署在Tomcat中,上下文路径是“Lab”。所以我试图访问该服务,如:

http://localhost:8080/Lab/cservice/emp

I am getting

我正进入(状态

No service was found.

采纳答案by supergaosong

I think you should make sure that your Employee class have a correctly "@" remark. just like below:

我认为你应该确保你的 Employee 类有一个正确的“@”注释。就像下面一样:

@XmlRootElement(name="cservice")

public class Employee (){
    private String employeeId;
    private String employeeName;
    ...


@XmlElement(name="employeeId")
    public void setEmployeeId(String employeeId){
        ...
    }
    public String getEmployeeId(){
        return this.employeeId;
    }

@XmlElement(name="employeeName")
    public void setEmployeeName(String employeeId){
        ...
    }
    public String getEmployeeName(){
        return this.employeeName
    }
...
...
}

and I suggest you to check WEB-INF/beans.xml & WEB-INF/applicationContext.xml.

我建议您检查 WEB-INF/beans.xml 和 WEB-INF/applicationContext.xml。

回答by Mengyu ZHang

Make sure your request url endpoint match your server endpoint.

确保您的请求 url 端点与您的服务器端点匹配。

combine url in web.xml and beans.xml result your endpoint

在 web.xml 和 beans.xml 中结合 url 结果你的端点