2016-09-16 3 views
2

私たちの新しいアプリケーションは、複数のデータベースでマルチテナントを使用しています。 URLにテナントIDを付けることで、適切なデータソースを選択することができます。動的アプリケーションパス

URLの名前空間は、/apiの代わりに、/{id}/apiに変更されます。このような方法を使用すると、動的になります。それで、動的な@ApplicationPathを使用することは可能ですか?

@Pathアノテーションの変数を使用するのと同じように、@ApplicationPath("/tenants/{id}/api")のようなものを書くことができますか?

+2

私はあなたが '@ ApplicationPath'にパスパラメータを持つことはできないと思います。 '@Path("/{id}/tenants ")' –

+0

@CássioMazzochiMolin:そうですね、 '@ApplicationPath'内の変数を使うことは、とにかくサポートされていない(私はインターネットでこの問題について何ら言及していない)。 –

答えて

0

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 
    } 
} 
関連する問題