我正在使用VRaptor
来实现 Web 服务。我正在寻找一种将服务前缀(例如/v1/*
)添加到URI
. 我想在全球范围内不使用@Path("/v1/")
.
如何使用这个框架和 Tomcat 来做到这一点?是否可以使用webxml
(servlet 映射?)。
提前致谢。
另一种方法是专门研究 VRaptor's PathAnnotationRoutesParser
,即:
@Alternative
@Priority(Interceptor.Priority.LIBRARY_BEFORE+10)
public class CustomRouterParser extends PathAnnotationRoutesParser {
protected CustomRouterParser() {
this(null, null);
}
@Inject
public CustomRouterParser(Router router, Environment environment) {
super(router);
this.environment = environment;
}
@Override
protected String[] getURIsFor(Method javaMethod, Class<?> type) {
return "CUSTOM-PREFIX" + super.getURIsFor(javaMethod, type);
}
}
您可以在http://www.vraptor.org/en/docs/components/#customizing-vraptor查看更多示例。最好的