Results 1 to 4 of 4

Thread: HttpSession passivation and ApplicationContextAware

  1. #1
    Join Date
    Oct 2005
    Posts
    8

    Default HttpSession passivation and ApplicationContextAware

    Hi,

    I've got a bean "mybean" that is stored in a HttpSession and that should be ApplicationContext aware to access a singleton "mySingleton".

    My question regards what happens if my http session is passivated.

    If I implement the ApplicationContextAware interface, i guess I will have no valid reference on the WebApplicationContext any more when the bean will be activated, since the WebApplicationContext is not serializable

    I've implemented HttpSessionActivationListener for "mybean" like this :
    Code:
    public void sessionDidActivate(HttpSessionEvent event) {             
           mySingleton = event.getSession().getServletContext().getAttribute("mySingleton");
     }
    I'm not satisfied with this solution because I have to store mySingleton in the ServletContext.

    any idea about a "more Spring"solution that enables a direct access to the WebApplicationContext ?

  2. #2
    Join Date
    Aug 2004
    Location
    Germany
    Posts
    24

    Default

    If you want to use the HttpSessionActivationListener you can do

    Code:
    public void sessionDidActivate(HttpSessionEvent event) {
      applContext = WebApplicationContextUtils.getWebApplicationContext(event.getSession().getServletContext());
    }
    Now you can use "getBean" on the ApplicationContext to access yout singleton-bean.

    I am also still looking for a 'nice' solution, because I would not like to make my beans dependend on HttpSessionActivationListener.

  3. #3
    Join Date
    Oct 2005
    Posts
    8

    Default method injection

    I've just discovered the method injection and as far as I can understand it, I can replace the ApplicationContextAware implementation by an abstract method like this :
    Code:
    protected abstract MySyngleton getMySingleton();
    
    <bean id="myBean" class="MyBean">
    <lookup-method name="getMySingleton" bean="mySingleton" />
    </bean>
    It works fine but I wonder if I should expect some side effects between CGLIG and serialization when passivation will occur ?

  4. #4

    Default

    Old post, but I have the same problem...

    The method injection is unfortunately not the solution (from Spring's documentation) :

    Finally, beans that have been the target of method injection cannot be serialized.

Similar Threads

  1. Replies: 0
    Last Post: Oct 6th, 2005, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •