struts2 委托spring代理action<转>

让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>

posted @ 2012-11-21 14:11  人生如若初见  阅读(325)  评论(0编辑  收藏  举报