Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用spring在struts2操作中注入依赖项?_Java_Spring_Struts2 - Fatal编程技术网

Java 如何使用spring在struts2操作中注入依赖项?

Java 如何使用spring在struts2操作中注入依赖项?,java,spring,struts2,Java,Spring,Struts2,我有一个基于struts2的遗留web应用程序(主要使用注释)。调试时,我发现所有依赖项(如服务层和dao层) 在struts 2操作中自动注入。我原以为struts.xml中一定会定义一些spring拦截器来执行此操作 但我没有在那里找到任何与spring相关的拦截器。同样,在web.xml中,我没有找到任何相关的东西来做这种工作。 我不确定struts2操作中如何注入依赖项(使用spring) 我可以在类路径中看到struts2-convention-plugin-2.2.3.1.jar文件

我有一个基于struts2的遗留web应用程序(主要使用注释)。调试时,我发现所有依赖项(如服务层和dao层) 在struts 2操作中自动注入。我原以为
struts.xml
中一定会定义一些spring拦截器来执行此操作

但我没有在那里找到任何与spring相关的拦截器。同样,在
web.xml
中,我没有找到任何相关的东西来做这种工作。 我不确定struts2操作中如何注入依赖项(使用spring)


我可以在类路径中看到
struts2-convention-plugin-2.2.3.1.jar
文件。这是否意味着
filterDispatcher
会在运行时查找这个jar,如果找到了它,就将依赖项注入到操作中。在此过程中,是否有拦截器也有帮助?

必须有一个拦截器..,它在action类之前执行,并使用Java反射API..或Struts 2反射执行此依赖项注入工具。。http://struts.apache.org/2.3.4/struts2-plugins/struts2-convention-plugin/apidocs/org/apache/struts2/convention/ReflectionTools.html
检查拦截器堆栈。

请参考
struts2-spring-plugin-x.x.jar
struts plugin.xml
,您可以找到关于对象工厂和自动连接拦截器的配置。它使用struts2的插件功能,您可以从Struts指南中搜索“插件”以了解详细信息。

如果依赖项注入是用spring完成的,请查看

如果没有,struts2有自己的

看一看

我们能看到配置的示例,以及注入依赖项的对象的示例吗?那么你说web.xml中没有定义spring侦听器吗?@fmucar我在web.xml中看到ContextLoaderListener,它根据web.xml中的参数contextConfigLocation参数读取给定的xam文件。但这将只实例化单例bean,而不是原型或请求范围。正确的?要在实际中注入原型bean,必须通过拦截器或插件来完成。您有struts2 spring插件作为您的依赖项吗?这是集成struts2+弹簧的一种方法。您的应用可能正在使用某些自定义解决方案。Listener管理所有Springbean,但仍然需要在某个点截获操作,以便能够注入依赖项。给我们看看configuration@MSach:您可以查找
struts2 spring plugin
,因为该插件负责控制spring DIrajesh,我可以在类路径中查看struts2-convention-plugin-2.2.3.1.jar文件。这是否意味着filterDispatcher会在运行时查找这个jar,如果找到了它,则会在操作中注入依赖项。对吗?在这个过程中,是否有拦截器也有帮助?Shen是正确的。ObjectFactory负责创建Struts2使用的所有操作、拦截器、结果和类型转换器。默认情况下,Struts2使用反射来创建这些对象,但是Spring和Guice的插件允许这些框架创建这些对象。