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.
any idea on when a release version will be built for JSR-330?
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.
Guice 3.0 is the reference implementation for JSR-330 and is released.
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?
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".
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.