A Quick Tip: Automatic Injection/Binding for Google Guice


News: A Quick Tip: Automatic Injection/Binding for Google Guice

  1. Do you think the Spring Framework is to heavy for your needs? But you want to use Dependency Injection?

    Then we are on the same road, but due a lot of experiences with Spring I missed one Feature: Classpath Scanning.

    After some research I found, that the only guys who thought about this topic, were the guys from Sonatype. They showed the dynamic possibilites with Guice. After starting using it, I found the dependencies of their toolkit were to heavy for "only Classpath Scanning" and Binding. There were also some design descisions in the APIs which I don't like, but it's only my personal opinion. The Extension is pretty nice!

    So I started to create my own project. I wanted to have a Guice Module, which binds a Classpath Scanner, the Packages and the Features.

    The result is a project (hosted at Github http://github.com/manzke/guice-automatic-injection) which provides 3 Classpath Scanner Implementations.

    1. My own, which is using pure Java-Classes and ASM
    2. Reflections, which is using Javassit (supports parallel Scanning!)
    3. Sonatype-Extension

    They are all spread into their own projects, which you can add find in Maven.

    After a successful scanning all Guice Modules annotated with @GuiceModule, will be installed into a child Injector. All classes annotated with @AutoBind will be bound to all inherited interfaces. You can also name it, which would lead to a named binding and overwrite the interfaces, which should be used.

    And if you don't want to use all Features, just overwrite the StartupModule and bind only the Features you want or your own.

    So stop typing the Bindings yourself, let "Automatic Injection/Binding for Guice" do it for you! :)



  2. Further Documentation and Descriptions can be found here:


    and here:


  3. why introduce extra dependency such as asm and sonatype?

  4. You don't need the dependency. You could create your own. But you need a framework to read the classes. If you would read all classes by the classloader, you would load unnecessary classes into your memory.

    You could create a Classpath Scanner which uses an own Classloader, which would skip them after reading.

    So it is your choice if you want the dependency.

    (every framework which read classes uses javaassist or asm)

  5. So you only need the Core-Module and one of the Scanners. (pure ASM, Reflections or Sonatype)

  6. You can now use the JSR330 and Guice-Annotations (@Singleton, @Named) to configure the binding of the beans.

    Testcases und Examples were extended.


    Still fighting with the Maven Release Plugin. :)

  7. After a lot of problems with Maven, git/Github and Windows read here, how I could do my first Maven Release for Automatic Injection/Binding for Guice.



  8. Now with GuicyFruit-Integration[ Go to top ]

    You can use now JSR250-Annotations and JNDI-Bindings, due a nice Integration of GuicyFruit into the Automatic Injection/Binding for Google Guice.