找不到网址观察者的请求 [英] Can't find the request for url Observer

查看:100
本文介绍了找不到网址观察者的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Apache CXF的示例REST服务,但是以某种方式我无法调用该服务.我的实现类是

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

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;
    }
}

我的web.xml文件是

My web.xml file is,

<!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>

我部署在Tomcat中,上下文路径为"Lab".所以我试图像这样访问服务:

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

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

我得到

No service was found.

推荐答案

我认为您应确保您的Employee类带有正确的"@"标记.就像下面这样:

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

@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
    }
...
...
}

,我建议您检查WEB-INF/beans.xml& WEB-INF/applicationContext.xml.

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

这篇关于找不到网址观察者的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆