六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 164|回复: 0

struts2 委托spring代理action<转>

[复制链接]

升级  32%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
16
 楼主| 发表于 2012-12-29 11:29:10 | 显示全部楼层 |阅读模式
<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>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表