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的快速入门文档,用起来挺简单的。
貌似这种写法来自于C或者C++
用 Annotation, 如果配置文件改变了, 需要重新编译原代码. 还是用 xml 配置要来得方便.
可以,你只需要通过Guice的Provider机制就可以很容易的实现这个需求。可以参考Guice 中对HttpServletRequest的处理。
现在好多应用服务器都是使用jdk1.5一下的版本,不支持annotation,guice只能作为研究对象,但不多很快普及使用的。
请问,如果如果一个已有的类,比如我要使用其他Jar包里的类,里面没有guice的annotation那不就无法直接使用注入来使用这个类了?
没有配置文件,前途是光明的。
static class SingletonHolder {
static Singleton instance = new Singleton();
}
把SingletonHolder定义成private会不会更好些
侵入是必然的,但如果性能上面真的有100倍的话,那前途非常光明的。
无配置文件是比较好,J2EE中的配置文件太多了 不过读代码的时候,可能就费点劲了
确切的说是以前的lazy loading方法在并发下要么不正确,要么效率低,这种Holder方法提供了一个既正确又比较高效的机制
huangyou 写道 无配置文件这点就很好
把依赖关系从代码中抽出来是为了保持代码的纯净,消除容器api侵入。 依赖关系由ioc框架维护。 配置文件拿掉后,很容易用一个另外的ioc框架替换, annotation在代码里面就是另外一回事了。
应该是重设计,轻风格,欣赏简洁易懂的代码。
无配置文件这点就很好
annotation比硬编码好在哪里?
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.
spring代码的确一般,但设计还是不错的,hibernate,seam也是 牛人们似乎都喜欢设计很多类,但里面的代码风格和质量却不怎么关注(很多地方完全可重构), 看不惯seam把那个大括号写在第二行...
看不出来这样写的好处,哪位老大来指点一下
annotation又被乱用了。