Spring和Struts2框架整合有关问题
Spring和Struts2框架整合问题
问题1.在整合Spring和Struts2后,为什么我的action类没有写注解@Component("xxAction"),还是可以被spring自动装配?
--------------------------------------------------------------------------------------
问题2.struts.xml采用通配符的方式:
struts在执行<action>时先通过name属性找容器中对应名字的bean;
那么我在beans.xml中可以这样来对应吗?
-------------------------------------------------------------------------------------------------------
那么这种xml对应的annotation怎么来配置?
------解决方案--------------------
不是struts执行action找bean,而是spring容器实例化bean的时候根据class找action。
注解形式:
@Controller("xxxAction")
@Scope("prototype")
xml形式:
<bean id="xxxAction" class="com.xx.xx.XXXAction" scope="prototype">
<property name="xxxService" ref="xxxService" />
</bean>
问题1.在整合Spring和Struts2后,为什么我的action类没有写注解@Component("xxAction"),还是可以被spring自动装配?
--------------------------------------------------------------------------------------
问题2.struts.xml采用通配符的方式:
<action name="*" class="struts2.test.action.TestAction" method="{1}">
<result name="success">/{1}.jsp</result>
</action>
struts在执行<action>时先通过name属性找容器中对应名字的bean;
那么我在beans.xml中可以这样来对应吗?
<bean id="AddOk" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id="Add" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id=" Exchange" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id=" FirstPage" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id="List" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id="RegisterOk" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id=" Register" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id="Login" class="struts2.test.action.TestAcion" scope="prototype"></bean>
<bean id="DeleteOk" class="struts2.test.action.TestAcion" scope="prototype"></bean>
-------------------------------------------------------------------------------------------------------
那么这种xml对应的annotation怎么来配置?
------解决方案--------------------
不是struts执行action找bean,而是spring容器实例化bean的时候根据class找action。
注解形式:
@Controller("xxxAction")
@Scope("prototype")
xml形式:
<bean id="xxxAction" class="com.xx.xx.XXXAction" scope="prototype">
<property name="xxxService" ref="xxxService" />
</bean>