java - 不太了解Struts2 XWork中依赖注入(inject)的机制

标签 java struts2 dependency-injection xwork

我是IOC新手,目前正在学习Struts2框架的源代码。 通过学习,我对框架有了一些基本的了解,例如 ActionInvocau 处理程序拦截器等。

但是当我试图弄清楚神秘的(至少对我来说)依赖注入(inject)部分时,我完全迷失了。

com.opensymphony.xwork2.inject 包中指定的注入(inject)机制很难理解。 ContainerImpl.inject(Object) 到底是如何完成所有工作的? 或者,我应该从哪里开始理解 DI?

最佳答案

我个人发现this资源有用。对于其他喜欢挖掘旧的、非常旧的用户指南的人可以下载 Guice 1.0 User's Guide.pdf 。正如戴夫提到的

S2 uses an old (old!), hacked version of Guice for its DI.

因此,您可以使用此页面作为 Dependency Injection 的起点与Struts2。

附注:

关于ContainerImpl.inject(Object)

Injects dependencies into the fields and methods of an existing object.

这并不神秘,因为像 Spring 这样的 Guice 会 Autowiring 一个 bean。像 Guice 这样的 Spring 可以使用注释来连接对象依赖关系。

关于java - 不太了解Struts2 XWork中依赖注入(inject)的机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27658537/

相关文章:

forms - 支柱 2 : updating a list of objects from a form with model driven architecture

wcf - 使用 WCF 的 StructureMap?

angularjs - Angular 翻译 : $translate undefined in controller

java - 如何在 reader.readLine() 期间检测第一行和最后一行?

java - 静态和非静态初始化代码块有什么区别

java - 在java中读取特定单词之间的字 rune 件

session - 在 session 中存储对象 - struts2

json - java.lang.IllegalStateException : getInputStream() has already been called for this request + Struts2 and JSON

java - Maven Artifact 是否从依赖项的父 pom 继承?

c# - ServiceProvider 不为 transient EF 上下文释放内存