Using @Context, @Provider and ContextResolver in JAX-RS

前端 未结 5 1260
感情败类
感情败类 2020-12-02 15:35

I\'m just getting acquainted with implementing REST web services in Java using JAX-RS and I ran into the following problem. One of my resource classes requires access to a s

5条回答
  •  攒了一身酷
    2020-12-02 16:11

    If anyone is using Resteasy this is what worked for me.

    If you add something like this:

    ResteasyContext.pushContext(StorageEngine.class, new StorageEngine());
    

    into something like a jaxrs filter, it allows you to do something like this:

    @GET
    @Path("/some/path")
    public Response someMethod(@Context StorageEngine myStorageEngine) {
     ...
    }
    

    This is specific to Resteasy, which doesn't have something like SingletonTypeInjectableProvider.

提交回复
热议问题