【问题标题】:Scope 'session' is not active for the current thread - multi-threading当前线程的范围“会话”不活动 - 多线程
【发布时间】:2019-11-08 02:20:01
【问题描述】:

我有一个 java-spring web 应用程序,我使用了一些我无权访问的外部库。 在其中一个流程中,我创建了一个新线程并使用这个外部库。我得到一个例外:

有没有办法克服这个异常?

谢谢!

【问题讨论】:

    标签: java spring multithreading session


    【解决方案1】:

    遇到了同样的问题,遇到了:https://bekce.github.io/replacing-session-scope-with-thread-scope-in-spring-framework/

    “当您的应用程序还需要 Web servlet 以外的其他集成点时,会话范围的 bean 会出现问题”。

    然后我使用了来自 sping 的 SimpleThredScope. 的自定义范围 = "thread"

    在 bean 配置中,如下所示:

    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
          <property name="scopes">
              <map>
                  <entry key="thread">
                      <bean class="org.springframework.context.support.SimpleThreadScope"/>
                  </entry>
              </map>
          </property>
        </bean>
        <bean id="testA" class="com.concretepage.A"  scope="thread" />
    

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 2015-01-29
      • 2019-08-22
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      相关资源
      最近更新 更多