Inject @SessionScoped value into filter with Guice

ぃ、小莉子 提交于 2019-12-13 03:43:11

问题


I have a class hold value of a user in session

 @SessionScoped
 class UserSession{}

Now I have a LoginFilter to ensure some url accessed with user login

class LoginFilter{
   @Inject UserSession userSession;
   ...
}

Then Out of scope exception was thrown when I try to bootstrap jetty. How can I check if the session contains the UserSession object? I don't know the attribute name of UserSession class.


回答1:


You can inject a Provider<UserSession> instead of a plain UserSession.



来源:https://stackoverflow.com/questions/17333790/inject-sessionscoped-value-into-filter-with-guice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!