似乎applicationpath不支持動態段。最後,我們固定它通過使用sub-resources:
配置
@ApplicationPath("tenants")
public class TenantConfig extends ResourceConfig {
public TenantConfig(ObjectMapper mapper) {
//set provider + add mapper
register(TenantsController.class);
}
}
TenantsController
@Path("/{id}/api")
public class TenantsController {
//register all your controllers including path here
@Path("/somethings")
public Class<SomethingController> something() {
return SomethingController.class;
}
}
SomethingController
@Component
//Don't use @Path, as path info is already defined in the TenantsController
public class SomethingController {
//do your stuff here;
@GET
@Path("/{id}") //Path for this example would be /tenants/{id}/api/somethings/{id}
public JsonApiResult get(@PathParam("id") int id) {
//retrieve one something
}
}
我不認爲你可以在'@ ApplicationPath'中擁有路徑參數。但是你可以使用路徑參數'@Path(「/ {id}/tenants」)來啓動'@ Path'' –
@CássioMazzochiMolin:是的,我也開始認爲在@ ApplicationPath中使用變量是隻是不支持(無論如何,我在互聯網上沒有發現任何關於這個問題的提及)。 –