2014-08-27 44 views
0

我正在使用VRaptor來實現Web服務。 我正在尋找將服務前綴(例如/v1/*)添加到URI的方法。 我想在全球範圍內不使用@Path("/v1/")使用VRaptor3和Tomcat定義基本URI

如何使用這個框架和Tomcat來實現它?是否有可能使用webxml(servlet映射?)。

在此先感謝。

回答

1

的替代辦將被專門VRaptor的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看到更多的例子。最佳