java - Spring built-in replication support for session-scoped beans? -
i've posted this in spring forums, figured i'd give folks here shot @ adding reputation:
for plain old servlet apps operating in clustered environment (session replication/failover), it's practice "re-set" session attributes if they've been modified:
userpreferences prefs = (userpreferences)session.getattribute("userpreferences"); prefs.setinstantemail(true); session.setattribute("userpreferences", prefs);
this acts flag container session state has changed , replication required. here's reference wls documentation on subject.
an app i'm modifying uses spring support pojo+injection style of development , i'm not clear on how above practice translates. per spring docs, scoped beans dependencies, app uses <aop:scoped-proxy/>
inject session-scoped dependency. however, without direct access session, how changes dependency flagged container replication can occur? there built either proxy or web context support it? if not, have examples of how they're handling it?
thanks insight.
clarification based on axtavt's answer:
one of project's goals in following pojo+injection approach avoid direct dependencies on either java ee or spring classes. can imagine spring might expose hooks retrieving beans context provide place @ least track session-scoped beans have been used. possibility might declaring set of methods on session-scoped bean that, when invoked, trigger state change. not being intimately familiar spring, can guess @ seems possible without knowing technical details.
follow-on question after looking @ spring code:
can shed light on role servletrequestattributes
might play? looks getattribute
method tracks attributes have been retrieved , updateaccessedsessionattributes
method attempts "re-set" attributes believes have changed.
where no built-in support this.
from looking @ code, can manually follows:
requestattributes = requestcontextholder.currentrequestattributes(); string name = scopedproxyutils.gettargetbeanname("...your bean name...") synchronized (a.getsessionmutex()) { object o = a.getattribute(name, requestattributes.scope_session); a.setattribute(name, o, requestattributes.scope_session); }
Comments
Post a Comment