seata用的1.4.2版本,项目有用到了@RequestScope注解,没有这个注解,可以正常启动,但是加上这个注解,启动就会报错 “Scope 'request' 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: In this case, use RequestContextListener or RequestContextFilter to expose the current request.”,请问如何处理?
Q
[seata]seata1.4.2,项目中有@RequestScope注解,启动报错
6
A
回答
0
完整堆栈提交上来
9
完整堆栈.txt 跟seata的这个依赖有关系,seata-spring-boot-starter,去掉这个依赖,也可以正常启动,加上就报上面的错误
9
2
您好,这条回复是在回复我吗?带RequestScope注解的bean被排除在外了,那我项目中确实需要RequestScope,该怎么办呢
0
@Scope(value = WebApplicationContext.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.TARGET_CLASS) 试试
5
这样是可以启动的,只要去掉@RequestScope就能正常启动,但是我这个类需要@RequestScope注解,因为要创建请求作用域的bean,如果像您这样,改成单例bean的话,就会与业务不符。
2
是不是可以理解为带有RequestScope注解的项目,还不支持引入seata,因为从上述代码来看,这种类好像被手动移出了spring的扫描范围
4
你们试过 @RequestScope的bean中的method有@transactional注解或者业务自定义注解切面,可生效吗?
6
这个没试过,我们带@RequestScope的bean中只有查询,没有其他操作,所以不需要@transactional这个注解
9
methodinterceptor是持有了你的单例bean,而你的bean是多例的造成了这样的问题,你应该下沉globaltransactional注解到实际的查询接口,而不是最外层的多例bean中