读书人

Google Guice - 比Spring快100倍儿的I

发布时间: 2012-10-28 09:54:44 作者: rapoo

Google Guice - 比Spring快100倍的IoC容器
http://code.google.com/p/google-guice/

Google公司的Bob lee开发的轻量级IoC容器,其特点是:

1、速度快,号称是spring的100倍速度
2、无配置文件,实用JDK5.0的annotation描述组件依赖,简单,而且有编译器检查和重构支持
3、简单,代码量很少

http://code.google.com/p/google-guice/wiki/SpringComparison

这是Google guice和spring IoC容器的对比

另外xwork2.0已经集成了Google guice容器了。

http://docs.google.com/Doc?id=dd2fhx4z_5df5hw8

这是Google guice的快速入门文档,用起来挺简单的。 32 楼 Godlikeme 2007-03-01 annotation又被乱用了。 33 楼 nicemike 2007-03-02 看不出来这样写的好处,哪位老大来指点一下 34 楼 shaucle 2007-03-05 acdc 写道ajoo 写道
无论如何,欢迎任何对spring容器的竞争,因为spring的容器代码和设计确实不太漂亮。
同感,
但是要补充的一点是,哪怕出现了比Spring更好的框架, 目前一时半刻也很难撼动Spring的地位...更多的人考虑的该框架是否有足够的官方/非官方的技术支持,是否可以轻易的从市场招聘到懂该框架的开发人员.

spring代码的确一般,但设计还是不错的,hibernate,seam也是
牛人们似乎都喜欢设计很多类,但里面的代码风格和质量却不怎么关注(很多地方完全可重构),
看不惯seam把那个大括号写在第二行... 35 楼 hiver 2007-03-13 http://www.artima.com/forums/flat.jsp?forum=270&thread=198371

Google announced the open-source release of Guice, its internal Java dependency injection framework Guice.

Guice wholly embraces annotations and generics, thereby enabling developers to wire together and test objects with less effort than ever before. Annotations finally free you from error-prone, refactoring-adverse string identifiers.

Guice injects constructors, fields and methods (any methods with any number of arguments, not just setters). Guice includes advanced features such as custom scopes, circular dependencies, static member injection, Spring integration, and AOP Alliance method interception, most of which you can ignore until you need it.

An earlier version of Guice already powers Struts 2's plugin architecture. Google has been running Guice in mission critical applications for months, and now you can, too.

Guice lives at Google Code. From there, you'll find the user's guide, Javadocs, and download. Please direct any questions to the mailing list. 36 楼 gof95 2007-03-13 annotation比硬编码好在哪里? 37 楼 huangyou 2007-03-18 无配置文件这点就很好 38 楼 Godlikeme 2007-03-18 shaucle 写道acdc 写道ajoo 写道
无论如何,欢迎任何对spring容器的竞争,因为spring的容器代码和设计确实不太漂亮。
同感,
但是要补充的一点是,哪怕出现了比Spring更好的框架, 目前一时半刻也很难撼动Spring的地位...更多的人考虑的该框架是否有足够的官方/非官方的技术支持,是否可以轻易的从市场招聘到懂该框架的开发人员.

spring代码的确一般,但设计还是不错的,hibernate,seam也是
牛人们似乎都喜欢设计很多类,但里面的代码风格和质量却不怎么关注(很多地方完全可重构),
看不惯seam把那个大括号写在第二行...

应该是重设计,轻风格,欣赏简洁易懂的代码。
39 楼 Godlikeme 2007-03-18 huangyou 写道无配置文件这点就很好

把依赖关系从代码中抽出来是为了保持代码的纯净,消除容器api侵入。
依赖关系由ioc框架维护。
配置文件拿掉后,很容易用一个另外的ioc框架替换,
annotation在代码里面就是另外一回事了。 40 楼 xtwxgh 2007-03-22 huangyou 写道
无配置文件这点就很好 41 楼 xtwxgh 2007-03-22 引用
huangyou 写道
无配置文件这点就很好
42 楼 bouzouki 2007-03-23 JAVA_ED 写道intolong 写道ahuaxuan 写道
不得不佩服Bob Lee了,咱怎么就没有想到呢,呵呵,看来Bob Lee对java真的是相当的精通了,到现在还能创新单例模式,牛

牛是牛,不过感觉singleton的lazy loading用处不大。

通常lazy loading用在比较消耗资源的时候。生产环境下一般在容器启动时候就load了,越早发现问题越好,测试环境下可能有些作用。

不过就算是lazy loading有用,通常singleton里面只有getInstance(),也就是说即使把singleton作为类的静态实例缓存,也是在调用getInstance()时候才会加载,这不就是lazy loading想做的效果么。

除非你非要load singleton class,比如在singleton class里面写些别的静态方法或者使用反射load它,不过我不会这么做。

这种singleton lazy loading不是主要benefit concurrent才是正解

确切的说是以前的lazy loading方法在并发下要么不正确,要么效率低,这种Holder方法提供了一个既正确又比较高效的机制 43 楼 wldandan 2007-03-23 无配置文件是比较好,J2EE中的配置文件太多了
不过读代码的时候,可能就费点劲了 44 楼 rainlife 2007-04-04 ajoo 写道

有点犹豫的:
1。说是ultra-lightweight。可能是指代码量说的。从侵入性来讲,要求组件import Guice的Annotation,这不太lightweight——当然,从实用角度来讲也不一定就是大不了的问题。


侵入是必然的,但如果性能上面真的有100倍的话,那前途非常光明的。 45 楼 demon3780 2007-04-18
static class SingletonHolder {
static Singleton instance = new Singleton();
}

把SingletonHolder定义成private会不会更好些 46 楼 jetever 2007-04-19 没有配置文件,前途是光明的。 47 楼 xingxing444 2007-05-02 请问,如果如果一个已有的类,比如我要使用其他Jar包里的类,里面没有guice的annotation那不就无法直接使用注入来使用这个类了? 48 楼 javadev 2007-05-02 现在好多应用服务器都是使用jdk1.5一下的版本,不支持annotation,guice只能作为研究对象,但不多很快普及使用的。 49 楼 ecsoftcn 2007-05-02 xingxing444 写道请问,如果如果一个已有的类,比如我要使用其他Jar包里的类,里面没有guice的annotation那不就无法直接使用注入来使用这个类了?

可以,你只需要通过Guice的Provider机制就可以很容易的实现这个需求。可以参考Guice 中对HttpServletRequest的处理。 50 楼 Hejrcc 2007-05-17 用 Annotation, 如果配置文件改变了, 需要重新编译原代码.
还是用 xml 配置要来得方便. 51 楼 cosmo1987 2012-02-29 shaucle 写道acdc 写道ajoo 写道
无论如何,欢迎任何对spring容器的竞争,因为spring的容器代码和设计确实不太漂亮。
同感,
但是要补充的一点是,哪怕出现了比Spring更好的框架, 目前一时半刻也很难撼动Spring的地位...更多的人考虑的该框架是否有足够的官方/非官方的技术支持,是否可以轻易的从市场招聘到懂该框架的开发人员.

spring代码的确一般,但设计还是不错的,hibernate,seam也是
牛人们似乎都喜欢设计很多类,但里面的代码风格和质量却不怎么关注(很多地方完全可重构),
看不惯seam把那个大括号写在第二行...
貌似这种写法来自于C或者C++

读书人网 >软件架构设计

热点推荐