Problem: This injected dependency will always return 0 from SimpleController
This is an answer here that shows the actual solution.
You should modify SessionCountListener like this, and the above example will work:
public class SessionCounterListener implements HttpSessionListener {
@Autowired
private SessionService sessionService;
@Override
public void sessionCreated(HttpSessionEvent arg0) {
getSessionService(se).addOne();
}
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
getSessionService(se).removeOne();
}
private SessionService getSessionService(HttpSessionEvent se) {
WebApplicationContext context =
WebApplicationContextUtils.getWebApplicationContext(
se.getSession().getServletContext());
return (SessionService) context.getBean("sessionService");
}
}