在监听器中注入spring bean

今天要做一个启动tomcat时的一个初始化动作,用spring的@Resource标签直接报异常:
严重: Error configuring application listener of class xx.action.listener.JobListener

javax.naming.NameNotFoundException: Name xx.listener.JobListener is not bound in this Context

原来是在监听器启动之前得先加载spring-bean,所以把注解bean换成这样获取就OK:
WebApplicationContext appctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());

SimpleTriggerRunner simpleTriggerRunner = (SimpleTriggerRunner) appctx.getBean("simpleTriggerRunner");

你可能感兴趣的:(spring,bean,listener)