@javax.inject.Inject,新的注入依赖规范

5 篇文章 0 订阅

Announcing @javax.inject.Inject

 
I'm proud to announce a  new dependency injection specification backed by both Google Guice and Spring. You can catch  the official announcement over on the Google Code Blog:

 

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:

  • @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
One additional interface is specified for use in conjunction with these annotations:
  • Provider - Provides instances of a type T. For any type T that can be injected, you can also inject Provider.
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 our JSR proposal.

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.

This specification will address the last shortcoming of annotation-based dependency injection. You no longer have to import vendor-specific annotations.

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 说明

今天,我们为开发者提供了一个两全其美的选择。Google Gucie和SpringSource已经建立了合作的关系,让注入类在框架中的使用更加简便。

具体说明如下:

    * @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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值