Home > Atmosphere > Using Google Guice with Atmosphere

Using Google Guice with Atmosphere

Starting with Atmosphere 0.5, you can now use Google Guice to configure Atmosphere


Google Guice support is enabled by referencing the Guice filter GuiceFilter and an application specific ServletContextListener that extends from GuiceServletContextListener in the web.xml. For example, the web.xml may be as follows:


       <filter-name>Guice Filter</filter-name>
       <filter-name>Guice Filter</filter-name>


and the application specific servlet context listener may be as follows:

public class GuiceChatConfig extends GuiceServletContextListener {

    protected Injector getInjector() {
        return Guice.createInjector(new GuiceChatModule());


public class GuiceChatModule  extends ServletModule{

    protected void configureServlets(){
        Map params = new HashMap();
        params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "org.atmosphere.samples.guice");
        serve("/chat*").with(AtmosphereGuiceServlet.class, params);

That’s it. You can download the previously Atmosphere-Jersey sample, this time Guice enabled from here. For any questions or to download Atmosphere, go to our main site and use our Nabble forum (no subscription needed) or follow us on Twitter and tweet your questions there!

// // technorati:

Categories: Atmosphere
  1. December 18, 2009 at 9:58 am

    If you bind your Guice components, such as root resource classes, in the GuiceChatModule then it is not necessary to include the parameter for package scanning. See the following link for more details:


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: