我正在尝试使用 Spring 在我的网站中实现“记住我”功能。persistent_logins 表中的 cookie 和条目已正确创建。此外,当用户名显示在页面顶部时,我可以看到正在恢复正确的用户。
但是,一旦我尝试访问此用户在“记住”后返回时的任何信息,我就会收到 NullPointerException。看起来好像没有再次在会话中设置用户。
我的 applicationContext-security.xml 包含以下内容:
<remember-me data-source-ref="dataSource" user-service-ref="userService"/>
...
<authentication-provider user-service-ref="userService" />
<jdbc-user-service id="userService" data-source-ref="dataSource"
role-prefix="ROLE_"
users-by-username-query="select email as username, password, 1 as ENABLED from user where email=?"
authorities-by-username-query="select user.id as id, upper(role.name) as authority from user, role, users_roles where users_roles.user_fk=id and users_roles.role_fk=role.name and user.email=?"/>
我认为这可能与按用户名查询用户有关,但如果此查询不正确,登录肯定无法正常工作?
对此的任何帮助将不胜感激。
谢谢,齿轮。