Struts2与Spring的整合
•Struts2框架为配合与Spring3框架进行整合,提供了相应的拦截器。
•该组件名为StrutsSpringObjectFactory,位于struts2-spring-plugin-2.2.1.1.jar中
•通过在struts.xml中的声明,便可直接使用该组件以实现整合。
struts.xml
6 <struts> 7 <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"/> 8 <package name="strutsspring" namespace="/strutsspring" extends="struts-default"> 9 <action name="login" class="LoginAction"> 10 <result name="success">/success.jsp</result> 11 <result name="input">/index.jsp</result> 12 </action> 13 </package> 14 </struts>
ApplicationContext.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 6 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 7 8 <bean id="LoginService" class="model.LoginService"> 9 </bean> 10 11 <bean id="LoginAction" class="controller.LoginAction" scope="prototype"> 12 <property name="loginService" ref="LoginService"/> 13 </bean> 14 </beans>