我不是一个春天专家,我现在面临一个问题,我不明白...不理解春季SessionAttribute和自动装配
我有我的控制器一SessionAttribute“用户”,即自动连接到我的bean用户。 当我登录时,我的用户被填充一些值等。
当我注销时,我期望我的会话属性“用户”将被重置,但它保留其值。
那么问题在哪里?我的登出无法正常工作吗?或者是正常的,那么有人能解释我在春天发生了什么吗?
下面是一个代码示例,了解我的问题:
@Controller
@SessionAttributes("user")
public class HomeController
{
@Autowired
private User user;
// Session Attribute
@ModelAttribute("user")
public User setSessionAttribute()
{
LOGGER.debug("Adding user to session...");
return user;
}
...
}
编辑:注销示例代码和用户声明
我的用户声明如下:
@Component
public class User
{
...
}
要注销我有一个链接指向/ myapp/j_spring_security_logout,我已经实现了一个注销处理程序:
@Component
public class MyLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler
{
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException
{
//to check if user is in session, but it's not
Enumeration<String> e = request.getSession().getAttributeNames();
//some code needed to log out from my custom security manager
//kill the session (not spring session) and redirect to the specified url
agent.logout("/myapp/login");
super.onLogoutSuccess(request, response, authentication);
}
}
您如何注销?你可以发布代码注销 – Anugoonj
你的'User' bean在哪里声明? –