scope='request'的bean预加载冲突

来源:互联网 发布:深圳善达网络怎么样 编辑:程序博客网 时间:2024/06/01 18:49

Error creating bean with name ‘authenticationSuccessServlet’: 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;
情景:
我自定义了一个spring security中的AuthenticationSuccessHandle类
并在spring security中配置authentication-success-handler-ref
目的是在spring security认证完用户了之后调用自定义的AuthenticationSuccessHandle类中的方法,我想在Session中存放认证用户的id
自定义的AuthenticationSuccessHandle类,我在spring中配置的scope是request

问题描述:
这个scope为request的bean不能被当前线程调用,请将scope改成singleton

原因:
我在网上查到原因是,spring security需要在启动的时候就加载AuthenticationSuccessHandle类,然而spring只在有请求的时候才加载这个类,所以spring security就加载不到

解决方案:
将这个bean的scope改成singleton

0 0