This specification will address the last shortcoming of annotation-based dependency injection. You no longer have to import vendor-specific annotations.
Five years ago, Spring 1.0 brought Java dependency injection into the mainstream. Three years later, Google Guice 1.0 introduced annotation-based dependency injection and made Java programming a little easier. Since then, developers have had to choose between a) writing external configuration or b) importing vendor-specific annotations.
Today, we hope to give developers the best of both worlds. Google Guice and SpringSource have partnered to standardize a proven, non-controversial set of annotations that make injectable classesportable across frameworks. At the moment, the set of specified annotations consists of:
One additional interface is specified for use in conjunction with these annotations:
- @Inject - Identifies injectable constructors, methods, and fields
- @Qualifier - Identifies qualifier annotations
- @Scope - Identifies scope annotations
- @Named - String-based qualifier
- @Singleton - Identifies a type that the injector only instantiates once
You can check out an early draft of the specification. We deliberately left external dependency configuration out, so as not to quash ongoing innovation. We haven't formally submitted this standard to the JCP yet, but we plan to do so shortly. Standards wonks can read a draft of ourJSR proposal.
- Provider - Provides instances of a type T. For any type T that can be injected, you can also inject Provider.
The expert group will be inclusive and will work in the open. For example, our mailing list is publicly readable, and we host the specification at Google Code. Several industry players have already expressed interest in supporting this effort. Contact us if you'd like to help out.
Our hope is that this specification will not only improve interoperability between existing dependency injection frameworks and unify the Java community, but it will also lower the barrier to entry for new injector implementations and foster even more innovation in this space.
I'd like to thank Paul Hammant, Doug Lea, Tim Peierls, James Strachan, Hani Suleiman, and Jason van Zyl for their early reviews and official support. Special thanks goes to our partner in this endeavor SpringSource, especially Rod Johnson, and my fellow Googlers and Guicers Josh Bloch, Jesse Wilson, Kevin Bourrillion, and Dhanji Prasanna.
@javax.inject.Inject，一个新的注入依赖规范，既能支持Google Gucie，还能支持Spring。你可以在Google Code的博客上查看官方发布：
五年前，Spring 1.0将依赖注入带入主流。三年后，Google Guice 1.0推出了基于annotation的依赖注入，这使得Java编程变得更轻松。从此之后，开发者只能有两种选择：a）编写外部配置 b）导入vendor-specific 说明
* @Inject - Identifies injectable constructors, methods, and fields
* @Qualifier - Identifies qualifier annotations
* @Scope - Identifies scope annotations
* @Named - String-based qualifier
* @Singleton - Identifies a type that the injector only instantiates once