论坛首页 Java版 Spring

如何将Bean注入到BeanAction的FormBean里

浏览 1747 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2006-08-18
如果用普通的Action, 通过org.springframework.web.struts.DelegatingActionProxy之后就可以在Spring里配置Action了.
struts-config.xml里这样配置:
[code:1]
<action-mappings>
<action path="/hello" name="ttBean" parameter="getHello"
type="org.springframework.web.struts.DelegatingActionProxy" scope="request" validate="false">
<forward path="/test.jsp" name="success" />
</action>
</action-mappings>
[/code:1]
applicationContext.xml里:
[code:1]
<beans>
<bean id="testService" class="com.neusoft.smiasms.service.TestService" />

<bean name="/getHello"
class="org.apache.struts.beanaction.BeanAction">
<property name="testService">
<ref bean="testService" />
</property>
</bean>
</beans>[/code:1]
在Action里:
[code:1]
private TestService testService;

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {

String hello = testService.sayHello();
request.setAttribute("hello", hello);

return mapping.findForward("success");
}

public void setTestService(TestService testService) {
this.testService = testService;
}[/code:1]

现在想用BeanAction, 参照iBatis里的JPetStore, 因为action的class都是org.apache.struts.beanaction.BeanAction, 没法把Bean注入到FormBean里. 或许是有办法, 而我不知道.

不知道倒底能不能把Bean注入到FormBean里~~~~

现在只能在用的时候, 从ServiceFactory里get出来, 感觉没有直接注册的方便.
大家有什么好的提意?

   
最后更新时间:2006-08-18
把Bean注入到FormBean里你的作用是什么?
只有把Bean注入到Service或Action里的方法比较常用哦?
不明白你这样做的动机是什么?不理解:(
   
0 请登录后投票
最后更新时间:2006-08-18
单实例的form汗
   
0 请登录后投票
最后更新时间:2006-08-21
YuLimin 写道
把Bean注入到FormBean里你的作用是什么?
只有把Bean注入到Service或Action里的方法比较常用哦?
不明白你这样做的动机是什么?不理解:(


这里注入FormBean就相当于注入Action里了.
是一种BeanAction
iBatis里的JPetStore的做法.
   
0 请登录后投票
最后更新时间:2006-08-23
还是在Action里,也就是你的FormBean里用BeanFactory来getBean比较好,这样灵活,利于测试。
   
0 请登录后投票
论坛首页 Java版 Spring

跳转论坛:
JavaEye推荐