Java 使用Spring boot在侦听器内调用带@RequestScope注释的类

Java 使用Spring boot在侦听器内调用带@RequestScope注释的类,java,spring-boot,listener,requestscope,beancreationexception,Java,Spring Boot,Listener,Requestscope,Beancreationexception,org.springframework.beans.factory.BeanCreationException:错误 创建名为的bean “scopedTarget.MovimentAcaoEntradarNotBuilderImpl”:范围 对于当前线程,“请求”未处于活动状态;考虑定义一个 如果您打算从一个目录引用此bean,则此bean的作用域代理 独生子女;嵌套异常为java.lang.IllegalStateException:否 找到线程绑定请求:您是指请求属性吗 在实际web请求之

org.springframework.beans.factory.BeanCreationException:错误 创建名为的bean “scopedTarget.MovimentAcaoEntradarNotBuilderImpl”:范围 对于当前线程,“请求”未处于活动状态;考虑定义一个 如果您打算从一个目录引用此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();
    }
}

根据(仅当存在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官方文档的指导来解决您的问题