My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
JSR330  

Guice30
Updated Oct 16, 2011 by sberlin

JSR-330 Integration

New in Guice 3.0

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. Optional injection is not supported. Methods must be non-abstract, return void, and not have type parameters of their own. Additionally, method overriding differs in a key way: If a class being injected overrides a method where the superclass' method was annotated with javax.inject.Inject, but the subclass method is not annotated, then the method will not be injected.
@Named @Named Interchangeable.
@Qualifier @BindingAnnotation Interchangeable.
@Scope @ScopeAnnotation Interchangeable.
@Singleton @Singleton Interchangeable.
Provider Provider Guice's Provider extends JSR-330's Provider. Use Providers.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. Similarly, using both Provider interfaces can cause difficultly, since they are not interchangeable.

Comment by ben.sto...@gmail.com, Mar 14, 2010

any idea on when a release version will be built for JSR-330?

Comment by company....@gmail.com, Apr 6, 2011

please answer the above question, the reason I shied away from Guice is that it's not a standard unlike JBoss Weld which is complete implementation.

Comment by project member dha...@gmail.com, Apr 6, 2011

Guice 3.0 is the reference implementation for JSR-330 and is released.

Comment by janga...@gmail.com, May 18, 2011

So, the best-practices note "stick with Guice" can be removed and we can use plain JSR-330 in our code and just use guice as one possible implementation?

Comment by sloanla...@gmail.com, Sep 26, 2011

Pronounced as "juice"? Come on! Nothing in English that begins with the letters "gui" has a soft consonant sound like "j". They all sound like the hard "g". This name is better pronounced as "goose".

Comment by lucian.burja@gmail.com, May 25 (3 days ago)

This page says that JSR-330's @Inject enforces that methods must return void. But in the JSR, I see the opposite: methods annotated with @Inject may return any result and it will be ignored by the injector.

Please fix it.


Sign in to add a comment
Powered by Google Project Hosting