有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java任何人在resteasy中都会遇到不可用的根路径吗

我正在使用RESTEasy编写一个WebService示例,并设置根资源路径。但我发现,即使url中没有根路径,我仍然可以获得正确的资源

主要功能代码:

   NettyJaxrsServer netty = new NettyJaxrsServer();
    ResteasyDeployment deploy = new ResteasyDeployment();
    List<Object> resources = new ArrayList<Object>();
    resources.add(new UserService());
    deploy.setResources(resources);
    netty.setDeployment(deploy);
    netty.setPort(8180);
    netty.setRootResourcePath("/hello/");
    netty.setSecurityDomain(null);
    netty.start();

服务代码:

@Path("user")
@Produces(MediaType.APPLICATION_JSON)
public class UserService {

对于代码,url/user可以正常工作,无需添加根路径/hello。我检查了源代码;它自己添加根路径

源代码:

public static String getEncodedPathInfo(String path, String contextPath)
{
    if(contextPath != null && !"".equals(contextPath) && path.startsWith(contextPath))
        path = path.substring(contextPath.length());
    return path;
}

我的问题是RESTEasy为什么要这么做?我不明白


共 (0) 个答案