gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:10 25 4
gpt4 key购买 nike

我是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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com