在struts的action中使用spring的IOC容器管理类

struts-config.xml 配置文件如下
xml 代码
<?xml version="1.0" encoding="UTF-8"?>   
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
<data-sources />
<form-beans >
<form-bean name="TestForm" type="com.gavin.struts.form.TestForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="TestForm"
name="TestForm"
path="/test"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="ok" path="/form/test.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.gavin.struts.ApplicationResources" />
</struts-config>


其中最关键的地方是 action 的 type="org.springframework.web.struts.DelegatingActionProxy"
必须设置为spring的代理
spring的配置文件如下
xml 代码
<?xml version="1.0" encoding="UTF-8"?>   
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean name="/test" class="com.gavin.struts.action.TestAction">
<property name="log">
<ref bean="Log" />
</property>
</bean>
<bean id="Log" class="com.gavin.service.Log" />
</beans>

注意:
action 对应的类必须 设置name属性,而不是id ,这里的name必须和struts配置文件中action的path相同
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值