I am not sure there is another solution to this, but I thought I would throw it out there.
I am attempting to inject a service level bean into a listener. The listener is defined in the web.xml and wired in a Spring config file. Obviously, I can't define parameters in web.xml, but I have set the params in Spring.
On startup, the webapp instantiates the listener (and obviously does not set the bean). Then, Spring instantiates the listener and sets the bean, as expected. When contextInitialized is called, it is naturally called on the webapps instance of the listener (with no bean reference).
This behavior is obviously expected, and I have come up with 2 workarounds. One is to simply make the bean member a static (which works because contextInitialized() is called after Spring sets the bean). The second is to use the WebApplicationContext to find the bean by id. Both of these work, but they are not very elegant.
Does anyone know of a better way to do this?