struts2.2 与 guice3.0 整合
最近看到 Guice 出3.0,以前看过一点guice ,对guice 的感觉还不错。之前一直都在搞SSH,有一点腻。所以想换换口味。网上关于Spring与Struts 整合的例子铺天盖地,可是 Guice与Struts 整合的例子少的可怜。找了好长时间,还是没找到满意的答案,只能靠自己了,自已来吧。
因为之前做过guice2.0与struts2整合的小例子,所以觉得guice3.0的整合方法应该差不多。想着只要在 struts.xml 里面加上
,经过一翻尝试之后,结果这种方法是错误的。guice3.0变化比较大, 参考 guice官网 http://code.google.com/p/google-guice/wiki/Struts2Integration 的教程。
依赖:如果是maven只需要加下面的依赖
struts.xmlimport javax.inject.Inject;/** * * @author Basten Gao */public class TestAction { @Inject private TestService testService; public String execute() throws Exception { testService.doSomeThing(); return Action.SUCCESS; }}1 楼 yingzhor 2011-05-05 http://topic.csdn.net/u/20110504/21/ccfd924d-79b7-4ce8-b438-707cc073ef09.html?seed=804993049&r=73132619#r_73132619