如果用 WebApplicationContextUtils 的 getWebApplicationContext 方法总是返回null,不知道怎么解决
网上有说在 web.xml 中加 ContextLoaderServlet ,但是我发现新版本spring中已经没有ContextLoaderServlet了
自己回答,在web.xml配置Listener,再单独定义一个ListenerBean组件,包含静态引用,并定义get和set成员方法,
在applicationContext配置这个ListenerBean组件,并用xml注入的方式将bean组件注入给ListenerBean的静态引用
最后Listener就可以直接使用ListenerBean的这个静态引用了。
要不,你把自定义的LIstener也看做bean,然后再xml里配置,将你自定义的Listener的类里实现ApplicationContextAware接口,并且定义一个属性ApplicationContext
这种方法不行,如果Listener不在web.xml配置就不发挥作用