My favorites | Sign in
Google
                
Search
for
Updated Sep 07, 2009 by limpbizkit
Labels: Guice21
JSR330  

JSR-330 Integration

This documents an experimental, unreleased feature available in Guice SVN only

JSR-330 standardizes annotations like @Inject and the Provider interfaces for Java platforms. It doesn't currently specify how applications are configured, so it has no analog to Guice's modules.

Guice implements a complete JSR-330 injector. This table summarizes the JSR-330 types and their Guice equivalents.

JSR-330
javax.inject
Guice
com.google.inject
@Inject @Inject Interchangeable, but JSR-330 places additional constraints on injection points. Fields must be non-final. Methods must be non-abstract, return void, and not have type parameters of their own.
@Named @Named Not equivalent. Be careful to inject the same @Named that you bind.
@Qualifier @BindingAnnotation Interchangeable.
@Scope @ScopeAnnotation Interchangeable.
@Singleton @Singleton Interchangeable.
Provider Provider Guice's Provider extends JSR-330's Provider. Use Jsr330.guicify() to convert a JSR-330 provider into a Guice provider.

Best Practices

For now, stick with Guice's annotations and Provider interface.

Mixing JSR-330 and Guice annotations is supported, but discouraged. In particular, using both @Named annotations can be quite clumsy, as it is hard to identify whose @Named is applied to a particular field or parameter. Similarly, using both Provider interfaces can cause difficultly, since they are not interchangeable.


Sign in to add a comment