0

org.springframework.beans.factory.BeanCreationException:创建名为“scopedTarget.movi​​mentacaoEntradaRadarNotaBuilderImpl”的bean时出错:范围“请求”对于当前线程无效;如果您打算从单例中引用它,请考虑为该 bean 定义一个作用域代理;嵌套异常是 java.lang.IllegalStateException:未找到线程绑定请求:您是指实际 Web 请求之外的请求属性,还是在原始接收线程之外处理请求?如果您实际上是在 Web 请求中操作并且仍然收到此消息,那么您的代码可能在 DispatcherServlet/DispatcherPortlet 之外运行:在这种情况下,请使用 RequestContextListener 或 RequestContextFilter 来公开当前请求。

我需要在不删除@RequestScope 的情况下解决问题,这仅适用于这种情况,而不适用于整个项目。

@Component
@RequestScope
public class BuilderImplementation implements BuilderInterface {

    @Override
    public void build(){

    }

}

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MovimentacaoEntradaQueueStorageListener {

    private final @NonNull BuilderInterface builderInterface;

    public MessageStatus listen() {

        builderInterface.build();
    }
}

4

1 回答 1

0

根据(springs 文档,三个范围“请求”、“会话”和“全局会话”只有在存在 Web 感知的 ApplicationContext 时才有可能:

The scopes that are described in the following paragraphs are only 
available if you are using a web-aware Spring ApplicationContext 
implementation (such as XmlWebApplicationContext). If you try using these 
next scopes with regular Spring IoC containers such as the XmlBeanFactory 
or ClassPathXmlApplicationContext, you will get an IllegalStateException 
complaining about an unknown bean scope.

按照官方spring文档的指导来解决你的问题。

于 2019-12-28T13:29:09.890 回答