I need to change the user session object (SessionScoped bean - CDI) in the servlet, so I have to somehow get this bean. I used the injection as follows:
@Inject private UserSession user;
where UserSession is the SessionScoped CDI bean. custom methods are called from doPost or doGet methods. This works great; every time the @Inject annotation introduces the corresponding UserSession bean, but I donβt understand how this behavior is achieved.
I assumed that beans annotated with @Inject are only entered once (when the object is created - an instance of the servlet in this case), but this is obviously a false presumption.
So when are these beans introduced in the servlet? On request? And how does this approach avoid conflicts (one servlet instance β several threads to deal with it) when there are several UserSession objects?
source share