Announcement Announcement Module
No announcement yet.
ensure a session bean is loaded before any other session bean is referred Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ensure a session bean is loaded before any other session bean is referred

    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:

    public class Pool {
    	private AuthManager authManager;
    	public Pool() {}
    	public void init() {
    	// ----------     ----------     UserAuthenticationListener     ----------     ----------     ----------
    	public void onAuthentication(UserAuthenticationEvent event) {
    		String username = event.getUser().getUsername();
    		if(event.isLogin()) {
    		} else {
    	// ...
    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.

    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?

  • #2
    What about having your "other session bean" depending on this Pool bean? in this way, this Pool bean will be initialized before initializing the "other session bean".


    • #3
      Why does the Pool have to be a session scoped object? Wouldn't it be easier (and maybe cleaner) to only make the needed Map to store the state session scoped? That way you circumvent all the problems, as your listener is always there and upon the first UserAuthenticationEvent the user based map is created and tied to the lifetime of the session (so not sure what you need to cleanup extra as the bean gets destroyed automatically).