-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JSR330
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 or jakarta.inject |
Guice com.google.inject |
|
---|---|---|
@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 (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
orjakarta.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. UseProviders.guicify()
to convert a JSR-330Provider
into a GuiceProvider
.
Note 3:
- Prior to Guice 6.0, Guice only supported
javax.inject
.- Guice 6.0 supports both
javax.inject
andjakarta.inject
.- Guice 7.0+ only supports
jakarta.inject.
Prefer JSR-330's annotations and Provider interface.
-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community