Skip to content


Grails: Initializing & Destroying Session Scoped Services

Quick post…

I ran across the need to use a session scoped service in my grails app the other day and had quite a hard time finding out how to do some housekeeping/cleanup once a user’s session has expired.
I came across this post on the mailing list which was very helpful but I couldn’t really get this to work, but it helped me figure out what I should be searching for (in the spring docs)

Here is how I got things to work.

import org.springframework.beans.factory.InitializingBean
import org.springframework.beans.factory.DisposableBean

class MySessionScopedService implements InitializingBean,DisposableBean{

    static scope = "session"

    void afterPropertiesSet(){
        // ***********************
        // Initialization code goes here
        // ***********************
    }


    void destroy(){
        // ******************************
        // Housekepping / Cleanup code goes here
        // *******************************
    }

}

Hope someone will find this useful.

Posted in Programming.

Tagged with , , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. Tweets that mention Grails: Initializing & Destroying Session Scoped Services – train of thought -- Topsy.com linked to this post on February 12, 2011

    [...] This post was mentioned on Twitter by Robbie James and Robbie James, lucastex_grails. lucastex_grails said: Grails: Initializing & Destroying Session Scoped Services http://goo.gl/fb/i6qwe [...]



Some HTML is OK

or, reply to this post via trackback.