Christian Edward Gruber edited this page Jun 10, 2016 · 3 revisions

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.

@Inject @Inject Interchangeable with constraints (See Note 1)
@Named @Named Interchangeable.
@Qualifier @BindingAnnotation Interchangeable.
@Scope @ScopeAnnotation Interchangeable.
@Singleton @Singleton Interchangeable.
Provider Provider Guice's Provider extends JSR-330's Provider (See Note 2)

Note 1: JSR-330 places additional constraints on injection points. Fields must be non-final. Optional injection is not supported. Methods must be non-abstract 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.

Note 2: Guice's Provider extends JSR-330's Provider. Use Providers.guicify() to convert a JSR-330 Provider into a Guice Provider.

Best Practices

Prefer JSR-330's annotations and Provider interface.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.