zoukankan      html  css  js  c++  java
  • HttpSessionListener中获取Spring中的Bean

    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) {
    }
    }
  • 相关阅读:
    Shape详解
    C#装箱与拆箱
    C#值类型、引用类型的区别
    C#类型简述
    C# 关键字列表
    python图片转字符画
    软件测试面试题
    python关键字以及含义,用法
    JMeter的那些问题
    APP测试功能点
  • 原文地址:https://www.cnblogs.com/live365wang/p/2172298.html
Copyright © 2011-2022 走看看