我有一个具有不同资源类别的嵌入式Jetty / Jersey应用程序。我要给每个资源方法加上一些附加说明,并根据URI检索正确的方法说明。
某些代码:
@Path("resource1")
public class My1stResource {
@GET
@Path("/aMethod")
@Description("This is a method")
public static String getValue()
{
...
}
}
@Path("resource2")
public class My2ndResource {
@GET
@Path("/anotherMethod")
@Description("This is another method")
public static String getValue()
{
...
}
}
public class Whatever {
private static Server server;
public static void main(String args[]) throws DataException
{
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(My1stResource.class);
s.add(My2ndResource.class);
ResourceConfig config = new ResourceConfig(s);
this.server = new Server(8765);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
this.server.setHandler(context);
ServletContainer container = new ServletContainer(config);
ServletHolder apiServlet = new ServletHolder(container);
apiServlet.setInitOrder(1);
context.addServlet(apiServlet, "/api/*");
}
public static String GetDescription(String uri)
{
???
}
}
如何获取GetDescription中@Description注释的内容?如果这不可能:是否可以使用其他一些机制来实现自己的目标?
谢谢, Kc