Apache cxf 删除请求错误

Apache cxf delete request error

我正在尝试使用 @DELETE 请求,之后我使用 soapui 测试了一些简单的 Web 应用程序。使用此应用程序,我可以向数据库添加和获取 users/book。现在我正在尝试提出 @DELETE 请求,但我做不到。这是代码:

//UserServiceImpl

    @PersistenceContext
    private EntityManager em;

    @Override
    public void deleteUser(Long id) {
        if (null == id || id.longValue() < 1) {
            throw new IllegalArgumentException(" User id can not be null or less than zero. ");
        }

        User u = em.find(User.class, id);
        em.remove(u);

    }

//UserResource

    @Autowired
    private UserService userService;

    @DELETE
    @Path("/delete/{id}")
    public Response deleteUser(@PathParam("id") String id) {
        Response response;
        try {
            User user = userService.deleteUser(Long.valueOf(id));//here is the error
            if (user != null) {
                response = Response.status(HttpServletResponse.SC_OK).entity(user).build();
            } else {
                response = Response.status(HttpServletResponse.SC_NOT_FOUND).build();
            }
        } catch (IllegalArgumentException e) {
            response = Response.status(HttpServletResponse.SC_NOT_FOUND).build();
        }
        return response;
    }

我已经解决了我的问题。 UserServiceImpl 中的 delete 方法不能为 void.... 它必须是 public User deleteUser(Long id)。 Resource class中的另一个delete方法...只需要是void类型即可。在那里我不使用响应,我只是像这样打印结果:

System.out.print(Response.status(HttpServletResponse.SC_OK).entity(user).build());