?? 在struts 2中實現ioc - max on java - blogjava.htm
字號:
<DIV align=left>我有個問題: <BR><BR>你在文中提到“告知Struts
2運行時使用Spring來創建對象(如Action等”,但是例子中由spring創建的是業務邏輯的實現: <BR>< bean id
="chatService" class ="tutorial.ChatServiceImpl" />
<BR>為何要將業務接口注入Action中,我覺得直接在Action中調用也無妨啊,難道不允許容器“依賴”業務邏輯? <BR><BR>個人愚見,請指教
<BR> <A onclick='return SetReplyAuhor("AlleNny")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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>用注入的方式,修改配置文件即可 <A onclick='return SetReplyAuhor("Tendy")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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一下,應該有中文翻譯的。 <A
onclick='return SetReplyAuhor("Max")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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>這樣配置<ref
local="chatService" />, 他們之間的關聯關系會比較明確(這種關系至少在配置文件的映射上很直觀)
<BR>如想達到更簡潔的配置效果(放棄上面這種直觀的關聯關系)可以這樣配置(其他地方都不需要修改) <BR><bean id="chatService"
class="tutorial.ChatServiceImpl" autowire="byName"/> <BR><bean
id="chatAction" class = "tutorial.ChatAction" scope="prototype"
autowire="byName"/> <BR> <A
onclick='return SetReplyAuhor("Goingmm[匿名]")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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顯示不出來。 <A
onclick='return SetReplyAuhor("Sophia")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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。 <A
onclick='return SetReplyAuhor("Max")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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 麻煩了... <A
onclick='return SetReplyAuhor("praguesky")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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:))) <A
onclick='return SetReplyAuhor("聶永")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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 <A
onclick='return SetReplyAuhor("yangdamao")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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>那要看看你運行的后出什么異常,才知道問題所在。 <A
onclick='return SetReplyAuhor("Max")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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>你上面的例子我運行不了,< package
name ="Struts2_IoC" extends ="struts-default" >為什么是package name
="Struts2_IoC"??請指教. <BR>能不能給發個EMAIL,xiaomeng1027@163.com <A
onclick='return SetReplyAuhor("xiaolan")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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>總是提示這個錯誤,我快沒轍了!!! <A
onclick='return SetReplyAuhor("yangdamao")'
href="http://www.blogjava.net/max/archive/2006/12/28/90548.html#post">回復</A> <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> <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> <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過去的啊!!! <A
onclick='return SetReplyAuhor("yangdamao")'
href="http://www.blogjava.net/max/archive/2
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -