package com.tg.system;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.tg.module.member.bean.Member;
import com.tg.module.member.service.IMemberService;
public class DefaultSessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent arg0) {
Member member = (Member) arg0.getSession().getAttribute("member");
ApplicationContext ctx = WebApplicationContextUtils.
getRequiredWebApplicationContext(arg0.getSession().getServletContext());
IMemberService memberService = (IMemberService)ctx.getBean("memberService");
Member visitor = memberService.findByMemberId("1");
arg0.getSession().setAttribute("member", visitor);
System.out.println("成功监听Session创建!");
}
public void sessionDestroyed(HttpSessionEvent se) {
}
}
HttpSessionListener中获取Spring中的Bean
最新推荐文章于 2019-11-11 01:22:17 发布