spring整合struts2
来源:互联网 发布:js手动触发回车事件 编辑:程序博客网 时间:2024/06/04 19:29
struts2和spring的整合,关键点在于struts2中的action要纳入spring容器的管理中成为一个bean。
可以在struts2中配置:
<struts>
<constant name="struts.objectFactory" value="spring" />
</struts>
同时action的配置class='beanID',访问该Action时,会通过class对应值去spring中寻找相同id值的bean。
也可以复制struts2-spring-plugin-x-x-x.jar到WEB-INF/lib目录下。
在struts2-spring-plugin-x-x-x.jar中有一个struts-plugin.xml配置文件,该配置文件配置内容:
<struts>
<bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" />
<!-- Make the Spring object factory the automatic default -->
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.class.reloading.watchList" value="" />
<constant name="struts.class.reloading.acceptClasses" value="" />
<constant name="struts.class.reloading.reloadConfig" value="false" />
<package name="spring-default">
<interceptors>
<interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
<interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>
</interceptors>
</package>
</struts>
可以看出该spring插件的作用就是关联struts action和spring bean,在struts中就不必再配置 <constant name="struts.objectFactory" value="spring" />了。
1,action的class值应等于spring中的bean id值,实现关联,action由spring创建。
2,若查不到,则由该spring插件根据class的值创建action,并把该action赋给spring托管,在这种情况下action的创建不是由struts2完成,而是由插件完成,并且插件拥有把action纳入spring容器管理的功能,此时spring配置文件中可以不必配置action的bean了。
两种方式都使得action成为了spring中的一个bean实例。
所以,class既可以为beanId,也可以为类路径,当寻找到对应bean时可以直接作为bean访问,若寻找不到,则会由插件根据class类路径负责创建action实例并送给spring成为其管理的一个bean。
可以在struts2中配置:
<struts>
<constant name="struts.objectFactory" value="spring" />
</struts>
同时action的配置class='beanID',访问该Action时,会通过class对应值去spring中寻找相同id值的bean。
也可以复制struts2-spring-plugin-x-x-x.jar到WEB-INF/lib目录下。
在struts2-spring-plugin-x-x-x.jar中有一个struts-plugin.xml配置文件,该配置文件配置内容:
<struts>
<bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" />
<!-- Make the Spring object factory the automatic default -->
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.class.reloading.watchList" value="" />
<constant name="struts.class.reloading.acceptClasses" value="" />
<constant name="struts.class.reloading.reloadConfig" value="false" />
<package name="spring-default">
<interceptors>
<interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
<interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>
</interceptors>
</package>
</struts>
可以看出该spring插件的作用就是关联struts action和spring bean,在struts中就不必再配置 <constant name="struts.objectFactory" value="spring" />了。
1,action的class值应等于spring中的bean id值,实现关联,action由spring创建。
2,若查不到,则由该spring插件根据class的值创建action,并把该action赋给spring托管,在这种情况下action的创建不是由struts2完成,而是由插件完成,并且插件拥有把action纳入spring容器管理的功能,此时spring配置文件中可以不必配置action的bean了。
两种方式都使得action成为了spring中的一个bean实例。
所以,class既可以为beanId,也可以为类路径,当寻找到对应bean时可以直接作为bean访问,若寻找不到,则会由插件根据class类路径负责创建action实例并送给spring成为其管理的一个bean。
0 0
- Spring -- spring整合struts2
- Spring:Spring整合Struts2
- 【Spring】Spring整合Struts2
- EJB3,Spring,Struts2整合
- struts2+hibernate+spring整合
- Struts2 与 Spring 整合
- struts2 spring hibernate 整合
- Spring struts2 hibernate 整合
- struts2整合spring步骤
- spring/struts2整合
- spring 整合struts2
- spring + struts2 整合
- Struts2与Spring整合
- Struts2和Spring整合
- struts2+spring+hibernate整合
- Struts2+Spring整合
- struts2 spring整合注意事项。
- Struts2+Spring整合
- opencv读取文件路径
- Size Balanced Tree
- JavaScript中为何需要用var来申明变量
- 【动态规划】【图论】[NOIP模拟赛]独立集
- cocos2d-x 3.0 开发环境搭建(win7/win8)
- spring整合struts2
- Linux进程实时IO监控iotop命令详解(系列一)
- 屏蔽OTA包的时间戳检测
- 调节系统音量VC++(适合win和xp系统) 打开静音 增减和减小系统音量
- LeetCode(137) Single Number II
- 九度OJ 1075:斐波那契数列 (数字特性)
- Android_08_样式和主题
- POJ 1905 Expanding Rods 木棍膨胀
- PBOC 文件结构详解1