⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在struts 2中实现ioc - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<DIV align=left>我有个问题: <BR><BR>你在文中提到“告知Struts 
2运行时使用Spring来创建对象(如Action等”,但是例子中由spring创建的是业务逻辑的实现: <BR>&lt; bean id 
="chatService" class ="tutorial.ChatServiceImpl" /&gt; 
<BR>为何要将业务接口注入Action中,我觉得直接在Action中调用也无妨啊,难道不允许容器“依赖”业务逻辑? <BR><BR>个人愚见,请指教 
<BR>&nbsp;&nbsp;<A onclick='return SetReplyAuhor("AlleNny")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=AlleNny" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl01_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl01$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl01_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#90648">#</A>&nbsp;<A 
name=90648></A>re: 在Struts 2中实现IoC 2006-12-29 09:27 | <A 
id=AjaxHolder_Comments_CommentList_ctl02_NameLink target=_blank>Tendy</A><BR>
<DIV align=left>@AlleNny <BR>--- <BR>为何要将业务接口注入Action中, <BR>--- <BR>re: 
是业务接口的实现(tutorial.ChatServiceImpl) 注入 action <BR><BR>--- 
<BR>我觉得直接在Action中调用也无妨啊,难道不允许容器“依赖”业务逻辑? <BR>--- <BR>re: 在 action 中 new 
tutorial.ChatServiceImpl() 也行 <BR>但当你需要使用不同的实现时,要改源代码,还要编译 
<BR>用注入的方式,修改配置文件即可&nbsp;&nbsp;<A onclick='return SetReplyAuhor("Tendy")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=Tendy" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl02_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl02$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl02_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#90732">#</A>&nbsp;<A 
name=90732></A>re: 在Struts 2中实现IoC 2006-12-29 14:16 | <A 
id=AjaxHolder_Comments_CommentList_ctl03_NameLink 
href="http://www.blogjava.net/max/" target=_blank>Max</A><BR>
<DIV align=left>@AlleNny <BR>Tendy说得很正确,我来补充几点: <BR>1、松耦合(Loose 
coupling)可以给程序的测试和维护带来很多好处; <BR>2、通过Spring的IoC方式,可以简单地创建Singleton对象。 
<BR>建议读一下Martin Fowler所写的《Inversion of Control Containers and the Dependency 
Injection pattern》,你可以google一下,应该有中文翻译的。&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("Max")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=Max" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl03_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl03$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl03_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#90814">#</A>&nbsp;<A 
name=90814></A>re: 在Struts 2中实现IoC 2006-12-29 22:21 | <A 
id=AjaxHolder_Comments_CommentList_ctl04_NameLink 
href="http://www.blogjava.net/goingmm" target=_blank>Goingmm[匿名]</A><BR>
<DIV align=left>@"为何要将业务接口注入Action中"? 其实这也不是唯一的选择!! <BR><BR>这样配置&lt;ref 
local="chatService" /&gt;, 他们之间的关联关系会比较明确(这种关系至少在配置文件的映射上很直观) 
<BR>如想达到更简洁的配置效果(放弃上面这种直观的关联关系)可以这样配置(其他地方都不需要修改) <BR>&lt;bean id="chatService" 
class="tutorial.ChatServiceImpl" autowire="byName"/&gt; <BR>&lt;bean 
id="chatAction" class = "tutorial.ChatAction" scope="prototype" 
autowire="byName"/&gt; <BR>&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("Goingmm[匿名]")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 
href="http://www.blogjava.net/comment?author=Goingmm%5b%e5%8c%bf%e5%90%8d%5d" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl04_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl04$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl04_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#96518">#</A>&nbsp;<A 
name=96518></A>re: 在Struts 2中实现IoC 2007-01-29 15:44 | <A 
id=AjaxHolder_Comments_CommentList_ctl05_NameLink target=_blank>Sophia</A><BR>
<DIV 
align=left>新手上路,照着做了一遍,指出一个小遗漏,tutorial.ChatAction.java文件中缺少setter方法,导致页面上的list显示不出来。&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("Sophia")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=Sophia" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl05_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl05$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl05_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#96571">#</A>&nbsp;<A 
name=96571></A>re: 在Struts 2中实现IoC 2007-01-29 18:28 | <A 
id=AjaxHolder_Comments_CommentList_ctl06_NameLink 
href="http://www.blogjava.net/max/" target=_blank>Max</A><BR>
<DIV align=left>@Sophia <BR>可能你漏了什么,显示userNames应该不用setter。&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("Max")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=Max" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl06_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl06$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl06_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#103114">#</A>&nbsp;<A 
name=103114></A>re: 在Struts 2中实现IoC 2007-03-11 16:51 | <A 
id=AjaxHolder_Comments_CommentList_ctl07_NameLink 
target=_blank>praguesky</A><BR>
<DIV align=left>不能spring接管action吗...这样 2边都要配置action 麻烦了...&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("praguesky")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=praguesky" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl07_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl07$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl07_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#105116">#</A>&nbsp;<A 
name=105116></A>re: 在Struts 2中实现IoC 2007-03-20 23:07 | <A 
id=AjaxHolder_Comments_CommentList_ctl08_NameLink target=_blank>聂永</A><BR>
<DIV align=left>谢谢~ <BR>正是我所想要的.原来以为只有SPRING MVC才可以实现IOC,现在STRUTS实现了,可以舍弃SPRING 
MVC了。呵呵~ <BR>希望楼主,加油啊,期待老大的好文章的出现o:)))&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("聂永")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 
href="http://www.blogjava.net/comment?author=%e8%81%82%e6%b0%b8" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl08_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl08$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl08_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#105637">#</A>&nbsp;<A 
name=105637></A>re: 在Struts 2中实现IoC 2007-03-22 20:00 | <A 
id=AjaxHolder_Comments_CommentList_ctl09_NameLink 
target=_blank>yangdamao</A><BR>
<DIV 
align=left>我照著做,怎麼做不出來啊,我引入的是spring.jar包其他完全一樣啊!!----新手,剛接觸struts&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("yangdamao")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=yangdamao" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl09_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl09$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl09_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#105671">#</A>&nbsp;<A 
name=105671></A>re: 在Struts 2中实现IoC 2007-03-22 23:00 | <A 
id=AjaxHolder_Comments_CommentList_ctl10_NameLink 
href="http://www.blogjava.net/max/" target=_blank>Max</A><BR>
<DIV align=left>@yangdamao <BR>那要看看你运行的后出什么异常,才知道问题所在。&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("Max")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=Max" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl10_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl10$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl10_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#105936">#</A>&nbsp;<A 
name=105936></A>re: 在Struts 2中实现IoC 2007-03-23 17:25 | <A 
id=AjaxHolder_Comments_CommentList_ctl11_NameLink target=_blank>xiaolan</A><BR>
<DIV align=left>能不能用STRUTS2.06的做一个结合SPRING2的DEMO? <BR>你上面的例子我运行不了,&lt; package 
name ="Struts2_IoC" extends ="struts-default" &gt;为什么是package name 
="Struts2_IoC"??请指教. <BR>能不能给发个EMAIL,xiaomeng1027@163.com&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("xiaolan")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=xiaolan" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl11_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl11$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl11_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#105951">#</A>&nbsp;<A 
name=105951></A>re: 在Struts 2中实现IoC 2007-03-23 18:45 | <A 
id=AjaxHolder_Comments_CommentList_ctl12_NameLink 
target=_blank>yangdamao</A><BR>
<DIV align=left>HTTP Status 404 - /Struts2_IoC2/Chat.action <BR><BR>type Status 
report <BR><BR>message /Struts2_IoC2/Chat.action <BR><BR>description The 
requested resource (/Struts2_IoC2/Chat.action) is not available. 
<BR><BR>總是提示這個錯誤,我快沒轍了!!!&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("yangdamao")' 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回复</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.blogjava.net/comment?author=yangdamao" 
target=_blank>更多评论</A><BR><A id=AjaxHolder_Comments_CommentList_ctl12_DeleteLink 
href="javascript:__doPostBack('AjaxHolder$Comments$CommentList$ctl12$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=AjaxHolder_Comments_CommentList_ctl12_EditLink></A></DIV></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle><A title="permalink: re: 在Struts 2中实现IoC" 
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#106016">#</A>&nbsp;<A 
name=106016></A>re: 在Struts 2中实现IoC 2007-03-24 09:18 | <A 
id=AjaxHolder_Comments_CommentList_ctl13_NameLink 
target=_blank>yangdamao</A><BR>
<DIV align=left>請問一下是不是我哪裡配置錯了?可我是把上面的代碼copy過去的啊!!!&nbsp;&nbsp;<A 
onclick='return SetReplyAuhor("yangdamao")' 
href="http://www.blogjava.net/max/archive/2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -