问题描述
在公司项目开发中遇见spring 和struts2 集成问题spring context配置文件代码:<!-- 客户信息 --><bean id="CustomerAction"class="com.kuquo.app.customer.action.CustomerAction"autowire="byName"></bean><!-- 商品类别 --><bean id="GoodTypeAction"class="com.kuquo.app.good.goodType.action.GoodTypeAction"autowire="byName" ></bean><!-- 商品信息 --><bean id="GoodAction"class="com.kuquo.app.good.good.action.GoodAction" autowire="byName"></bean><!-- 商品信息 --><bean id="GroupgoodAction"class="com.kuquo.app.good.groupgood.action.GroupgoodAction" autowire="byName"></bean>在看struts2.xml:<!-- 商品类别 --><action name="goodType" class="com.kuquo.app.good.goodType.action.GoodTypeAction"><result name="list_goodType">/WEB-INF/page/good/goodType/list_goodType.jsp</result><result name="edit_goodType">/WEB-INF/page/good/goodType/edit_goodType.jsp</result><result name="find_goodType">/WEB-INF/page/good/goodType/find_goodType.jsp</result><result name="edit_goodType2">/WEB-INF/page/good/goodType/edit_goodType2.jsp</result></action><!-- 商品类别 --><action name="groupgoodType" class="com.kuquo.app.good.groupgoodType.action.GroupGoodTypeAction"><result name="list_goodType">/WEB-INF/page/good/groupgoodType/list_groupgoodType.jsp</result><result name="edit_goodType">/WEB-INF/page/good/goodType/edit_goodType.jsp</result><result name="find_goodType">/WEB-INF/page/good/goodType/find_goodType.jsp</result></action><!-- 商品品牌 --><action name="goodBrand" class="com.kuquo.app.good.goodBrand.action.GoodBrandAction" ><result name="list_goodBrand">/WEB-INF/page/good/goodBrand/list_goodBrand.jsp</result><result name="edit_goodBrand">/WEB-INF/page/good/goodBrand/edit_goodBrand.jsp</result><result name="find_goodBrand">/WEB-INF/page/good/goodBrand/find_goodBrand.jsp</result></action><action name="groupGoodBrand" class="com.kuquo.app.good.goodBrand.action.GroupGoodBrandAction"><result name="list_groupgoodBrand">/WEB-INF/page/good/goodBrand/list_groupgoodBrand.jsp</result><result name="edit_groupgoodBrand">/WEB-INF/page/good/goodBrand/edit_groupgoodBrand.jsp</result><result name="find_goodBrand">/WEB-INF/page/good/goodBrand/find_goodBrand.jsp</result></action>在struts2配置文件中action 标签中class 竟然又是一个类完全限定名,并且该action是多例的,我想问下这种情况下 action到底是交个spring 管理还是struts2 自己管理?为什么?
解决方案
在struts2配置文件中action 标签中class 竟然又是一个类完全限定名,并且该action是 多例的,我想问下这种情况下 action到底是交个spring 管理还是struts2 自己管理?为什么?struts2自己管理: 和spring集成步骤:1、先根据class去spring中查找同名的bean;2、如果找不到直接反射new
解决方案二:
struts2自己管理: 和spring集成步骤: 1、先根据class去spring中查找同名的bean; 2、如果找不到直接反射newacton交给spring管理应该是为了可以使用spring的ioc和aop。。。
解决方案三:
你这个是交给struts 自己管理没有托管给spring 如果要托管给spring 你必须要配置如例子applicationContext-actions.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"><bean name="fileAction" class="com.byd.action.FileAction" scope="prototype"><property name="baseService" ref="baseService" /></bean></beans>applicationContext-services.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- 树 --> <bean id="baseService" class="com.byd.service.impl.ICurdBaseServiceImpl"><property name="baseDao" ref="baseDao" /></bean><bean id="webService" class="com.byd.service.impl.BaseServiceImpl"><property name="baseDao" ref="baseDao" /></bean></beans>applicationContext-dao.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- 树 --><bean id="baseDao" class="com.byd.dao.CurdBaseDaoImpl"><property name="sqlMapClient" ref="sqlMapClient" /></bean></beans>
解决方案四:
struts的其他配置呢?