范围“会话”;对于当前线程不活跃

发布于 2025-01-07 14:47:10 字数 1933 浏览 0 评论 0原文

我有两个 Spring 应用程序:客户端和服务器。服务器应用程序上是服务,客户端应用程序上是视图逻辑。两个应用程序应通过网络服务进行通信,但由于错误而无法正常工作

请求处理失败;嵌套异常是 org.springframework.remoting.jaxws.JaxWsSoapFaultException:错误 创建名称为“scopedTarget.jcrSession”的 bean:范围“session”为 当前线程不活动;考虑定义一个作用域代理 如果您打算从单例中引用此 bean;嵌套的 异常是 java.lang.IllegalStateException:没有线程绑定请求 发现:您是否指的是实际的请求属性之外的属性 Web 请求,或处理原始请求之外的请求 接收线程?如果您实际上是在网络请求中进行操作 并且仍然收到此消息,您的代码可能正在外部运行 DispatcherServlet/DispatcherPortlet 的:在本例中,使用 RequestContextListener 或 RequestContextFilter 暴露当前 请求。

在服务器应用程序上,我

<bean name="jcrSession" factory-bean="sessionFactory" factory-method="login" scope="session" destroy-method="logout" >
    <aop:scoped-proxy/>
</bean>

在服务器应用程序的 web.xml 中使用 JCR 会话(会话范围 bean),

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

当我在浏览器中访问服务器应用程序生成的 WSDL 文件时,一切正常。当我在本地使用服务器应用程序服务时(例如在服务器应用程序的控制器中),一切都正常。那么,当我尝试从远程应用程序通过 Web 服务访问服务时,为什么会出现此错误?

更新1 jcrSessionSessionFactory 类创建。然后,使用 springs @Autowired 将这个 jcrSession 自动装配到 DAO 对象。

Example of simplified `JcrSessionFactory`:
public class JcrSessionFactory {

    private Repository repository;
    private Credentials credentials;
    private Session session;

    public Session login() {
        session = repository.login(credentials);
        return session;
    }

    public void logout() {
        session.logout();
    }
}

此外,当我尝试在同一应用程序中自动装配服务并在 @PostConstruct 注释的方法中或在方法 afterPropertiesSet() 中的 InitializingBean 实现中使用它时,发生了同样的错误

I have two Spring applications: client and server. On server application are services, on client app is view logic. Both apps should communicate through web-services, but this did not work because of error

Request processing failed; nested exception is
org.springframework.remoting.jaxws.JaxWsSoapFaultException: Error
creating bean with name 'scopedTarget.jcrSession': Scope 'session' is
not active for the current thread; consider defining a scoped proxy
for this bean if you intend to refer to it from a singleton; nested
exception is java.lang.IllegalStateException: No thread-bound request
found: Are you referring to request attributes outside of an actual
web request, or processing a request outside of the originally
receiving thread? If you are actually operating within a web request
and still receive this message, your code is probably running outside
of DispatcherServlet/DispatcherPortlet: In this case, use
RequestContextListener or RequestContextFilter to expose the current
request.

On server app i'm using JCR Session (session scoped bean)

<bean name="jcrSession" factory-bean="sessionFactory" factory-method="login" scope="session" destroy-method="logout" >
    <aop:scoped-proxy/>
</bean>

in web.xml of server app I have

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

When I access WSDL files produced by server app in browser, everything is OK. When I use server app services locally (e.g. in controller on server app) everything is also OK. So why this error occurs, when I try to access services through web-services from remote app?

Update1
jcrSession is crated by SessionFactory class. Then this jcrSession is autowired to DAO objects using springs @Autowired.

Example of simplified `JcrSessionFactory`:
public class JcrSessionFactory {

    private Repository repository;
    private Credentials credentials;
    private Session session;

    public Session login() {
        session = repository.login(credentials);
        return session;
    }

    public void logout() {
        session.logout();
    }
}

Also, same error occured when I tried to autowire service in same app and use it in method annotated by @PostConstruct or in implementation of InitializingBean in method afterPropertiesSet()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文