shiro session listener

package com.xyz.service.shiro;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ShiroSessionListener implements SessionListener {
	@Override
    public void onStart(Session session) {//会话创建时触发
        log.error("会话创建:" + session.getId());
    }
    @Override
    public void onExpiration(Session session) {//会话过期时触发
    	log.error("会话过期:" + session.getId());
    }
    @Override
    public void onStop(Session session) {//退出/会话过期时触发
    	log.error("会话停止:" + session.getId());
    }  

}
<!-- sessionManager -->
	<bean id="redisSessionManager"
		class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
		<property name="sessionDAO" ref="redisSessionDAO" />
		<!-- Collection<SessionListener> listeners -->
		<property name="sessionListeners">
			<list>
				<ref bean="shiroSessionListener" />
			</list>
		</property>
 	</bean>

相关推荐