Hello,
I'm facing the following problem and haven't found any solution (nor on these forums, nor on the net).
I have a bean, Pool, that stores String->Object pairs, and fills and empties that map when the user logs in and logs out.
A session bean manages user autentication for the application, and upon user login, notifies all its listeners.
The idea is that the pool should register itself with the authManager, to be notified when a user logs in and logs out. These two events trigger the code in the two handleUser*() methods.
This is the pool:
The problem is that the pool, which I annotated as being a session bean, gets loaded too late (only when another class requires it through an @Autowired reference) to register itself on the authManager, and so it misses the user login - while it knows about the user logout.Code:@DependsOn("Registry") @Scope("session") @Service() public class Pool { @Autowired private AuthManager authManager; public Pool() {} @PostConstruct public void init() { authManager.addUserAuthenticationListener(this); } // ---------- ---------- UserAuthenticationListener ---------- ---------- ---------- @Override public void onAuthentication(UserAuthenticationEvent event) { String username = event.getUser().getUsername(); if(event.isLogin()) { handleUserLogin(username); } else { handleUserLogout(event.getUser().getUsername()); } } // ... }
This pool is designed to be almost independent and so could be loaded as early as the session has finished being created; how do I force Spring to load it that soon?
An ugly solution would be to put an @Autowired Pool pool; in another bean that is surely loaded before a user can login, but I'd like something cleaner.
Any suggestion?


Reply With Quote
