繁体   English   中英

在Jersey / Struts应用程序中为404

[英]404 in Jersey/Struts application

我正在尝试使用Jersey为我的struts应用程序提供一个简单的Web服务。

当我调用客户端操作时,出现以下错误

com.sun.jersey.api.client.UniformInterfaceException
Message: GET http://localhost:8080/shumer/rest/employee/get returned a response status of 404

web.xml中的servlet声明

<servlet>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>spring.autowire</param-name>
        <param-value>byName</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

服务器资源

@Path("employee")
public class EmployeeResource {

    @Autowired
    EmpDao empDao;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Employee> get(@QueryParam("empCode") String empCode) throws Exception {

            EmpCriteria criteria = new EmpCriteria();
            criteria.setEmpCode(empCode);


            return empDao.searchByCondition(criteria);
        }

}

客户行动

public class EmployeeClientTestAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

        Client client = Client.create();
        WebResource resource = client.resource("http://localhost:8080/shumer/rest/employee/get");

        String employees= resource.accept(MediaType.APPLICATION_JSON)
        .get(String.class);

        System.out.println(employees);

        request.setAttribute("employees", employees);

        return mapping.findForward("successful");
    }

}

我已经尝试过在EmployeeResource @Path批注中使用带/get和不带/get以及资源URL的末尾,带和不带/的情况。 我的猜测是,我必须声明要在哪里放置我的资源,以便Jersey servlet处理它们,但我无法弄清楚。 朝着正确方向的观点将不胜感激。

编辑

我已经将以下init-param添加到servlet元素中,但它仍然不起作用(此包是我的资源类所在的位置)

<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>shumer.rest.resource</param-value>
</init-param>

在get方法中,写入@Path(“ / get”)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM