Struts2+Spring集成中Action的管理

来源:互联网 发布:图片尺寸修改软件 编辑:程序博客网 时间:2024/05/16 18:43
一般而言我习惯用Struts2的Spring plugin集成,步骤如下:
先在web.xml中加入
<listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>
然后在struts.xml中加入
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
就可以了。但是我一直有个疑问,spring中bean默认是单例的,但是struts2 action为了多线程安全考虑,肯定不能是单例,应该是每次生成一个新的实例,后来查看StrutsSpringObjectFactory以及相关的代码才发现,如果在struts action的配置文件中<action name=".." class=".."/>中class写的如果是完整的包名和类名的话就是struts创建action对象,如果是spring配置文件中的bean的名字的话就是spring创建,顺序是先从spring中找,找不到再从struts配置文件中找。
原创粉丝点击