使用注释@EventListener
,我们是否仍需要向ServletContext
添加一个列表器?
喜欢这个监听器类:
@Component
public class LoginListener {
@Autowired
UserService us;
@EventListener
public void onApplicationEvent(AuthenticationSuccessEvent event) {
String userName = ((UserDetails) event.getAuthentication().getPrincipal()).getUsername();
System.out.println("lastloginspec : " + userName + " : 00 : " + LocalDateTime.now());
}
}
答案 0 :(得分:0)
我需要做的就是在HttpSessionEventListener
到ServletContext
addListener method
servletContext.addListener(new HttpSessionEventListener());