gpt4 book ai didi

spring - 我们如何从 Spring session 范围的 bean 中获取 bean 对象?

转载 作者:行者123 更新时间:2023-12-05 02:23:13 24 4
gpt4 key购买 nike

我正在尝试从 spring session scoped bean 中获取 bean。据我所知,基于 session 范围实例化的 Beans 通过 HTTP session 存在。那么如何从 Http Session 中获取这个 bean 对象。

最佳答案

您可以访问 ApplicationContext 并从那里检索 bean。

    ApplicationContext context = RequestContextUtils.getWebApplicationContext(request);
SessionInfo info = context.getBean("SessionInfo");-->Whatever bean you want

关于spring - 我们如何从 Spring session 范围的 bean 中获取 bean 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24593906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com