您的位置:首页 > 编程语言 > Java开发

struts2 委托spring代理action<转>

2012-11-21 14:11 411 查看
让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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: