1
A
回答
1
我不做春天,但在正常JSF/JSP/Servlet的,你会抓住HttpSessionBindingListener
这一点。基本上,您需要给会话范围bean一个static List<Bean>
属性并相应地实现该接口,以更新valueBound()
和valueUnbound()
方法中的static
列表。
您可以在this answer找到详细的代码示例。
0
这里是我想出了一个解决方案利用弹簧:
我进行正常的春季单例的bean称为SessionBeanHolder。 这个bean拥有我的会话bean的列表。 当用户登录时,我将会话bean添加到我的SessionBeanHolder中。
在Spring中引用会话bean时,实际上是指代理。 因此,使这项工作的关键是获取底层bean以添加到SessionBeanHolder中。
下面是示例代码:
注:我的会话bean被称为SessionInfo。
@Scope(value="singleton")
@Component
public class SessionBeanHolder {
static Set<SessionInfo> beans;
public SessionBeanHolder() {
beans = new HashSet<SessionInfo>();
}
public Collection<SessionInfo> getBeans() {
return beans;
}
public void addBean(SessionInfo bean) {
try {
this.beans.add(removeProxyFromBean(bean));
} catch (Exception e) {
e.printStackTrace();
}
}
// Fetch the underlying bean that the proxy refers to
private SessionInfo removeProxyFromBean(SessionInfo proxiedBean) {
if (proxiedBean instanceof Advised) {
try {
return (SessionInfo) ((Advised) proxiedBean).getTargetSource().getTarget();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
return proxiedBean;
}
}
}
当然,只要你想添加的会话Bean或者获取所有Bean的列表,只需在自动装配和SessionBeanHolder使用它的方法。
@Autowired
SessionBeanHolder sessionBeanHolder;
相关问题
- 1. 获取在Spring中实现通用接口的所有bean
- 2. 如何在JSF 2中获取所有会话范围的bean?
- 3. webpy中的会话 - 获取所有类中的用户名
- 4. 获取所有CDI bean
- 5. 获取所有现有客户到WCF
- 6. 如何迭代并获取会话中的所有用户名
- 7. NHibernate:获取所有打开的会话
- 8. InternetExplorer | IE.au3获取会话的所有cookie
- 9. 从所有IEnumerables中获取所有对象在所有IEnumerable中
- 10. Spring获取所有@Entity类
- 11. ASP.NET:如何删除所有用户的所有会话变量?
- 12. 获取所有PHP会话列表session_id
- 13. 如何获取用户的所有最近会话
- 14. 获取所有用户的所有约会或获得一个房间的所有约会
- 15. 注销的NodeJS所有用户会话
- 16. 从hybridauth获取所有用户数据
- 17. 从WEB API获取所有用户
- 18. 如何从Openfire获取所有用户?
- 19. 从instagram获取所有用户照片
- 20. 从LDAP获取所有用户
- 21. 从网站获取所有用户
- 22. 从Active Directory PrincipalContext获取所有用户
- 23. 从Active Directory获取所有用户?
- 24. Codeigniter - 获取所有用户会话数据
- 25. Larvael等效会话所有用户
- 26. 如何获取会话中的所有已初始化的托管bean?
- 27. 获取Active Directory中的所有用户
- 28. 在Spring中从另一个会话获取会话bean
- 29. Spring不从JAR导入所有bean实现
- 30. 打印加载的所有Spring bean