监听器使用spring的bean

在监听器启动之前得先加载spring-bean,所以注解在监听器里是不能用的。

可以通过下面的方法获取需要的bean

public void contextInitialized(ServletContextEvent sce) {
            WebApplicationContext appctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
            KhiTmOrdercntService khiTmOrdercntService = (KhiTmOrdercntService) appctx.getBean("khiTmOrdercntService");
        }
posted @ 2016-05-23 16:17  sz_zzm  阅读(387)  评论(0编辑  收藏  举报