我有两个 Spring 应用程序:客户端和服务器。在服务器应用程序上是服务,在客户端应用程序上是视图逻辑。两个应用程序都应该通过 Web 服务进行通信,但这由于错误而不起作用
请求处理失败;嵌套异常是 org.springframework.remoting.jaxws.JaxWsSoapFaultException:创建名称为“scopedTarget.jcrSession”的 bean 时出错:范围“会话”对于当前线程无效;如果您打算从单例中引用它,请考虑为该 bean 定义一个作用域代理;嵌套异常是 java.lang.IllegalStateException:未找到线程绑定请求:您是指实际 Web 请求之外的请求属性,还是在原始接收线程之外处理请求?如果您实际上是在 Web 请求中操作并且仍然收到此消息,则您的代码可能在 DispatcherServlet/DispatcherPortlet 之外运行:在这种情况下,请使用 RequestContextListener 或 RequestContextFilter 来公开当前请求。
在服务器应用程序上,我正在使用 JCR Session(会话范围 bean)
<bean name="jcrSession" factory-bean="sessionFactory" factory-method="login" scope="session" destroy-method="logout" >
<aop:scoped-proxy/>
</bean>
在服务器应用程序的 web.xml 中,我有
<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 服务访问服务时,为什么会发生此错误?
Update1
jcrSession
是按SessionFactory
类创建的。然后jcrSession
使用 springs 自动连接到 DAO 对象@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();
}
}
此外,当我尝试在同一个应用程序中自动连接服务并在由方法注释的方法@PostConstruct
或在InitializingBean
方法的实现中使用它时,发生了同样的错误afterPropertiesSet()