Hi Vishwanath,
This class name is org.springframework.web.context.support.ServletContextAttributeExporter.
You can inject collaborators into "attributes" property, and then you can use ServletContext.getAttribute in ServletContextListener, in this way you'll not have any dependency to Spring Framework code in your ServletContextListeners.
Vishwanath Murthi wrote:Hi kengkaj,
Yes. This works, but I'm wondering if DI would ever work in ServletContextListener...
From my understanding, DI should get triggered sometime. But is it even before the ServletContextListener is initialized?
Normally, Spring can only DI to its managed beans. ServletContextListeners objects are not created by Spring, so normally we cannot use DI.
There is a workaround by using AutowireCapableBeanFactory.autowireBeanProperties method, but the consequence is your code will have dependency to Spring.
For example, we can use DI in
Servlet by using the following example codes in init method:
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional