WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
摘至:http://blog.csdn.net/taijianyu/article/details/3176263 如果您想要在自己所定义的Servlet类别中使用Spring的容器功能,则也可以使用 org.springframework.web.context.ContextLoaderListener,例如在web.xml中使用< listener>标签加以定义: ... org.springframework.web.context.ContextLoaderListener ... ContextLoaderListener预设会读取applicationContext.xml,您可以指定自己的定义档,只要在中指定"contextConfigLocation"参数,例如: ... contextConfigLocation /WEB-INF/beans-config.xml, → /WEB-INF/demo-service.xml ... 接着您可以在自定义的Servlet中使用 org.springframework.web.context.support.WebApplicationContextUtils,从 ServletContext中取得org.springframework.web.context.WebApplicationContext,例如: WebApplicationContext ctx = WebApplicationContextUtils. getRequiredWebApplicationContext( this.getServletContext()); WebApplicationContext实作了ApplicationContext介面,是Spring专为Servlet的Web应用程式设计的 ApplicationContext实作类别,在取得WebApplicationContext之后,您可以利用它来取得Bean定义档中定义的 Bean实例,例如: Date date = (Date) ctx.getBean("dateBean");
XXXSysDbLogListenerImpl implements XXXDbLogListener onReceive(LogUserBean userLogBean) logFacade.saveUserLog(userLogBean); onReceive(LogOperationBean operationLogBean) logFacade.saveOperateLog(operationLogBean);