java - Spring storing an object in session -
after logging user object, user able choose 1 of multiple accounts, once user select 1 of accounts want application work specific account. there way store object account in session spring any controller can have access variable @ time?
you use session beans.
first interface set , object:
public interface accountholder { public void setaccount(account account); public account getaccount(); }
then implementation of interface:
public class accountholderimpl implements accountholder { private account account; public void setaccount(account account) { this.account = account; } public account getaccount() { return account; } }
define session-scoped bean in @configuration
:
@bean @scope(value="session", proxymode=scopedproxymode.interfaces) public accountholder accountholder() { return new accountholderimpl(); }
after can use following in controllers:
@autowired private accountholder accountholder;
Comments
Post a Comment