Archive for December, 2009

Using Google Guice with Atmosphere

December 17, 2009 1 comment

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