我在使用这个简单的 RestEasy 服务时遇到问题:
@Path("/")
public interface UserService {
@POST
@Path("/add")
@Consumes(MediaType.APPLICATION_JSON)
Response add(User user);
@POST
@Path("/update")
@Consumes(MediaType.APPLICATION_JSON)
Response update(User user);
@GET
@Path("/get/{id}")
@Produces(MediaType.APPLICATION_JSON)
Response get(@PathParam("id") long id);
@GET
@Path("/getAll")
@Produces(MediaType.APPLICATION_JSON)
Response getAll();
}
基本上,上面的代码可以工作,但是当我将 @Path("/")
更改为 @Path("/user")
并访问资源时,例如:
http://localhost:8080/user/add
它抛出错误404
。与原来有效的 http://localhost:8080/UserService/add
不同。
我在代码中遗漏了什么吗?
最佳答案
也许你可以尝试一下
http://localhost:8080/UserService/user/add
对于@Path(/用户)
关于java - 访问rest资源时出现404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13713889/