可以在
org.glassfish.jersey.server.model包中找到适用于Jersey 2.x的新API 。
我可以想到的一些等效项:
AbstractResource
==Resource
IntrospectionModeller.createResource
==我相信Resource.from(baseResource.class)
AbstractResourceMethod
==ResourceMethod
resource.getSubResourceMethods()
==getChildResources()
,实际上只返回一个List<Resource>
AbstractSubResourceLocator
==似乎不存在。我们只需检查上面的子资源,看看它是否是定位器for (Resource childResource: resource.getChildResources()) {if (childResource.getResourceLocator() != null) { ResourceMethod method = childResource.getResourceLocator(); Class locatorType = method.getInvocable().getRawResponseType();}}
您还可以使用枚举
ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR检查它是否等于
ResourceMethod.getType()
if (resourceMethod.getType() .equals(ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR) {}这就是我能想到的,以匹配您所得到的。
import com.wordnik.swagger.annotations.ApiOperation;import org.glassfish.jersey.server.model.Resource;import org.glassfish.jersey.server.model.ResourceMethod;public class ApiScanner { public static void main(String[] args) { ApiScanner scanner = new ApiScanner(); scanner.xyz(); } public void xyz() { Resource resource = Resource.from(baseResource.class); abc(resource.getPath(), resource); } public void abc(String uriPrefix, Resource resource) { for (ResourceMethod resourceMethod: resource.getResourceMethods()) { String uri = uriPrefix; System.out.println("-- Resource Method --"); System.out.println(resourceMethod.getHttpMethod() + "t" + uri); ApiOperation api = resourceMethod.getInvocable().getDefinitionMethod() .getAnnotation(ApiOperation.class); } for (Resource childResource: resource.getChildResources()) { System.out.println("-- Child Resource --"); System.out.println(childResource.getPath() + "t" + childResource.getName()); if (childResource.getResourceLocator() != null) { System.out.println("-- Sub-Resource Locator --"); ResourceMethod method = childResource.getResourceLocator(); Class locatorType = method.getInvocable().getRawResponseType(); System.out.println(locatorType); Resource subResource = Resource.from(locatorType); abc(childResource.getPath(), subResource); } } }}


