首页 文章

404在Jersey / Struts应用程序中

提问于
浏览
0

我正在尝试使用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");
    }

}

我已经尝试了这个有和没有 /get 和资源网址的结尾,并且在EmployeeResource @Path注释中有和没有前导 / . 我的猜测是,有一个地方我必须声明我的资源被涂在哪里,以便泽西servlet处理它们,但我无法弄明白 . 正确方向的一点将非常感激 .

EDIT

我已经将以下init-param添加到servlet元素,它仍然无法正常工作(这个包是我的资源类所在的位置)

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

1 回答

  • 0

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

相关问题