views:

174

answers:

1

Configuration: Guice 1.0, Apache Tomcat 6.0

I am currently manually injecting objects configured in a Guice Module, into my servlet, using this method:

public void init( ServletConfig config ) throws ServletException
{
    super.init( config );
    ServletContext sc = config.getServletContext();
    Injector injector = (Injector) sc
        .getAttribute( Constants.Guice.INJECTOR_APP_CONTEXT_KEY );
    injector.injectMembers( this );
}

How can I do the same into a HttpSessionAttributeListener (since it doesn't have any lifecycle methods) ?

Thanks

J

A: 

Event Listener is all about life-cycle events. For example, attributeAdded() is called right after an attribute is added to a session, similar to init() for Servlet.

It probably makes more sense to inject object into HttpSession. In that case, you want do it in HttpSessionListener.sessionCreated().

ZZ Coder
What is the difference between HttpSessionListener and HttpSessionAttributeListener ?
Jacques René Mesrine
One listens to the event for the session and the other for a single attribute in the session.
ZZ Coder