Spring Scope“请求”对于当前线程无效

我正在尝试创建一个请求范围的bean。那是代码:

@Configuration
public class Conf {

    @Bean public RequestContextListener list() {
        return new RequestContextListener();
    }

    @Bean
    public RequestContextFilter requestContextFilter() {
        return new RequestContextFilter();
    }


    @Bean
    @RequestScope
    public User currentUser() {

        User u = new User();
        return u;
    }
}

我总是收到错误消息:

引起原因:org.springframework.beans.factory.BeanCreationException:   创建名称为'scopedTarget.currentUser'的bean时出错:作用域   'request'对于当前线程无效;考虑定义一个   如果您打算从一个Bean引用此Bean的作用域代理,   单身人士嵌套异常是java.lang.IllegalStateException:否   找到线程绑定的请求:您是否在引用请求属性   在实际的Web请求之外,或在外部处理请求   最初的接收线程?如果您实际在   一个网络请求,但仍然收到此消息,您的代码可能是   在DispatcherServlet外部运行:在这种情况下,请使用   RequestContextListener或RequestContextFilter公开当前   请求。

I don't understand the problems. I Already exposed RequestContextListener and My bean is not injected, anywhere. So why this error?

The RequestScope Annotation is a shortcut for scope=request and proxy=target_class.