Guice BlazeDS’ MessageBroker

In a previous post (, I wrote about how to use Guice injection for Flex services.  I used web.xml to configure the MessageBrokerServlet and configured each Flex service to use Guice as a factory.  Since then, on this project, we’ve had to introduce new servlets.  Rather than continue to use web.xml’s verbose and fully-qualified-path based configuration, we moved to using Guice’s ServletModule class.  Here are the steps we followed.

  1. Ensure the guice-servlet.jar is included in your project and is deployed with your build.
  2. Add the Guice filter to web.xml.
  3. Create a servlet module, a class extending
  4. Override the configureServlets() method of ServletModule and add the message broker servlet configuration.
    final Map<String, String> params = new TreeMap<String, String>();
    params.put("services.configuration.file", this.context
    this.serve("/messagebroker/*").with(MessageBrokerServlet.class, params);

    1. Normally, servlets configured in Guice are tagged with @Singleton.  Since the MessageBrokerServlet is third party, it’s marked as a singleton here, in the module.
  5. Add the new module to the Guice servlet context listener, which should already be configured in web.xml.
  6. Remove the servlet and servlet-mapping from web.xml.
Posted in Guice by Connor Garvey at October 20th, 2009.
Tags: , , , ,

4 Responses to “Guice BlazeDS’ MessageBroker”

  1. An intriguing discussion is worth comment. I do believe that you need
    to publish more about this topic, it may not be a taboo subject but typically folks don’t speak about these issues. To the next! Cheers!!

  2. Pierre R says:

    I guess in this second scenario, I still need the “Guice factory” from the previous post.

    Thanks for your explanations !

  3. […] « Testing in Android with mock UI components Guice BlazeDS’ MessageBroker » adobe, blazeds, google, Guice, injection, Java, Redpoint, […]

Leave a Reply