【发布时间】:2017-07-18 16:16:12
【问题描述】:
在我的 Spring MVC 应用程序中,我添加了 spring 安全性
当我尝试在登录之前从数据库中获取 AppUser 以匹配给定的用户凭据时,我收到以下错误
[http-nio-8080-exec-12] ERROR org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter - An internal error occurred while trying to authenticate the user.
org.springframework.security.authentication.InternalAuthenticationServiceException: Error creating bean with name 'scopedTarget.getSession': Scope 'session' 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/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
根据给定的建议我添加了
@ComponentScan(scopedProxy = ScopedProxyMode.INTERFACES)
到我的 UserDetailService 但仍然遇到同样的错误
我配置的数据库 url 如下
db.local.url=http://neo4j:123456@localhost:7474
如果我使用硬编码用户进行身份验证,那么我可以登录 登录后,我可以与数据库进行各种通信
但在登录之前我收到上述错误
如何解决这个问题???
我的代码要点
https://gist.github.com/sazzadislam-dsi/6a6a21216e39184e54d0c074332bb372
【问题讨论】:
标签: spring-mvc spring-security