I'm building an online chat application in spring
just like the one on Facebook
. I want to create a bean with a property[Array] called active-users. Then performs the following:
- Whenever a user logs in, I'll add his/her userId into the array.
- When an other user logs in, I'll display the users that are currently online.
How do I create a bean which is available at all times?
For Ex : In servlets
, this can be achieved by using the Servlet context :
ServletContext context = request.getServletContext();
context.setAttribute("userId", "123");