Seam-Guice is now part of Seam

Google Guice support for Seam is now part of the Seam distribution!

It is available since the 2.1.2 release of Seam, as a part of the IoC module, but if you happen to need it, the best choice is to grab the latest 2.2.0.GA version which includes a fix for the disinjection issue.


The problem with disinjection was that the implementation injected values to the fields annotated with @Inject, but did not clear those values after the method call. The disinjection step here is required for exactly the same reason that Seam itself performs it on @In- and @Out-jected fields – to prevent a long-scoped Seam component from holding a reference to a (possibly short-living) Guice component.

Also, the presence of disinjection allows you to @Inject non-serializable properties into serializable components without having to worry about making those properties transient.

Configuration and Docs

The configuration did not change, except for one detail, which is the “guice” namespace URL declaration in the components.xml file:

view raw gistfile1.xml hosted with ❤ by GitHub

All components are now in the org.jboss.seam.ioc.guice package.

If you feel like checking the latest documentation of the Seam-Guice module, here is the link:

Thanks to Dan Allen who reviewed my code and spotted the disinjection issue.


Guicy Seam

Introducing @Guice annotation

You may already have heard about Seam being a “deep integration framework” and Google Guice providing lightweight dependency injection. The news is that you can now easily use Seam together with Guice.

The WebBeans specification is built upon concepts from both of those frameworks. Since Seam provides Spring support in the IoC module, why not to integrate Guice as well? Thinking this way I have implemented Guice support for Seam.

Quick Howto

The rule is fairly simple – if you want to use Guice injection in your Seam component, annotate it with the @Guice annotation.

public class MyGuicyComponent
@Inject MyObject myObject

view raw

hosted with ❤ by GitHub

For all Seam components annotated with the @Guice annotation, Guice injection will be performed automatically.

Great, but wait… which Guice injector will be used? Well, the one you provide. Just edit components.xml:

<guice:init injector="#{myGuiceInjector}/>

view raw


hosted with ❤ by GitHub

myGuiceInjector should be a Seam component that implements the Injector interface.

You may want to create it from a list of modules:

<guice:injector name="myGuiceInjector">

view raw


hosted with ❤ by GitHub

Of course you can also use an injector that is already used in other, possibly non-Seam, parts of you application. That was one of the reasons I implemented this integration – to tie other parts of an application that used Guice together with Seam.

To enable Seam and Guice integration, add seam-guice.jar library to your application. Do not forget to put guice-1.0.jar in as well 😉

Give it a try!

I have included more information on the wiki page. You can download seam-guice library and browse the source code. It is implemented as a simple interceptor. Let me know if you find a bug or a place for improvement.

If you like this solution, you can vote to make it part of the Seam project. You may also want to have a look at Guice and plain JSF integration and the Guice extension to JBoss Microcontainer.

Many thanks to Tomek, who introduced Guice to me, Kamil, for feedback and Adam, for encouraging me to blog about it 😉