Jersey 2.9设置每个会话的资源生命周期

时间:2014-07-06 20:28:32

标签: rest xmlhttprequest jersey

我有一个网络应用程序,我需要在每个会话中拥有一个我的资源实例。

我试着按照这里给出的例子,用我自己的类替换PerSessionRessource部分

https://jersey.java.net/documentation/latest/ioc.html

然而,似乎没有使用Provider,至少我可以看到我用我的第二个请求访问了我的资源类的新实例。

我尝试在应用程序中注册它,如下所示:

public class MyApplication extends ResourceConfig {

    public MyApplication() {
        System.out.println("Registering the application");
        register(PerSessionComponentProvider.class);


        register(new AbstractBinder() {
            @Override
            protected void configure() {
                bindFactory(HttpSessionFactory.class).to(HttpSession.class);
                bind(SessionInjectResolver.class)
                .to(new TypeLiteral<InjectionResolver<SessionInject>>(){})
                .in(Singleton.class);

        }
    }

            );
}

如何确保从客户端使用每个httprequest访问我的资源的同一实例。在Jersey 1.x中似乎有@PerSession注释,如何在Jersey 2.x中获得此功能?

提前致谢!

0 个答案:

没有答案