何事西风悲画扇 发表于 2013-1-4 02:23:08

struts2 委托spring代理action<转>

<div id="cnblogs_post_body">让spring代替struts2生成Action

struts2中提供了一个与spring进行集成的包,位于struts2 的lib下,叫做struts2-spring-plugin.jar。复制到当前目录的WEB-INF/lib下,然后配置struts.xml和applicationContext.xml

(1)在struts.xml的<action>配置中使用class属性指向Spring的<bean>元素:

    <action name="login" class="loginAction" >
         <result name="success">/success.jsp</result>
    </action>

(2)在applicationContext.xml中配置与<action>的class对应的<bean>元素:

   <bean id="loginAction" class="com.ss.usermgr.actions.LoginAction" scope="prototype">
      <property name="userManager" ref="userManager"/>
   </bean>

在web.xml中添加如下代码:
   <context-param>
      <param-name>contextConfigLocation</param-name>

      <!-- 我的applicationContext.xml放在src目录下,所以用classpath*: -->
      <param-value>classpath*:applicationContext-*.xml</param-value>
   </context-param>

<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
页: [1]
查看完整版本: struts2 委托spring代理action<转>