Spring - Injecting a dependency into a ServletContextListener

前端 未结 4 1020
心在旅途
心在旅途 2020-11-27 16:59

I would like to inject a dependency into a ServletContextListener. However, my approach is not working. I can see that Spring is calling my setter method, but l

4条回答
  •  失恋的感觉
    2020-11-27 17:40

    You cant have spring to do that, as already stated that is created by the server. If you need to pass params to your listener, you can define it in your web xml as a context-param

     
            parameterName
            parameterValue
        
    

    And in the Listener you can retrieve it like below;

     event.getServletContext().getInitParameter("parameterName")
    

    Edit 1:

    See the link below for another possible solution:

    How to inject dependencies into HttpSessionListener, using Spring?

提交回复
热议问题