﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Lilan's Blog-随笔分类-Java</title><link>http://www.blogjava.net/lilan1983/category/1543.html</link><description>Beyond Technology!!!</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 06:54:23 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 06:54:23 GMT</pubDate><ttl>60</ttl><item><title>实现拦截器</title><link>http://www.blogjava.net/lilan1983/archive/2005/12/28/25771.html</link><dc:creator>李岚</dc:creator><author>李岚</author><pubDate>Wed, 28 Dec 2005 11:02:00 GMT</pubDate><guid>http://www.blogjava.net/lilan1983/archive/2005/12/28/25771.html</guid><wfw:comment>http://www.blogjava.net/lilan1983/comments/25771.html</wfw:comment><comments>http://www.blogjava.net/lilan1983/archive/2005/12/28/25771.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lilan1983/comments/commentRss/25771.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lilan1983/services/trackbacks/25771.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 背景：拦截器是现在很多程序必须的一个东西。比如要在某个方法的前后做些处理，在一些特定的情况下可能会导致大量的重复代码。而假如我们拥有了类似拦截器一样的东西，那我们就可以任意在自己希望的方法的执行前后做我们自己的处理，比如日志，取得参数或者是事务等。&nbsp;实现：1．首先定义一个业务接口&nbsp;1/**&nbsp;*//**&nbsp;3&nbsp;*&nbs...&nbsp;&nbsp;<a href='http://www.blogjava.net/lilan1983/archive/2005/12/28/25771.html'>阅读全文</a><img src ="http://www.blogjava.net/lilan1983/aggbug/25771.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lilan1983/" target="_blank">李岚</a> 2005-12-28 19:02 <a href="http://www.blogjava.net/lilan1983/archive/2005/12/28/25771.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring和Webwork结合的方式</title><link>http://www.blogjava.net/lilan1983/archive/2005/11/23/21119.html</link><dc:creator>李岚</dc:creator><author>李岚</author><pubDate>Wed, 23 Nov 2005 05:52:00 GMT</pubDate><guid>http://www.blogjava.net/lilan1983/archive/2005/11/23/21119.html</guid><wfw:comment>http://www.blogjava.net/lilan1983/comments/21119.html</wfw:comment><comments>http://www.blogjava.net/lilan1983/archive/2005/11/23/21119.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lilan1983/comments/commentRss/21119.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lilan1983/services/trackbacks/21119.html</trackback:ping><description><![CDATA[<P><FONT size=2>前两种方式webwork的wiki里有，就不多说了,<A href="http://www.jscud.com/srun/news/viewhtml/4_2005_9/134.htm">点这里可以查看</A>。<BR>而以下的给出的思路是webwork mail list的讨论的一种方案，应该是最好的一种方案。<BR><BR>代码1：</FONT></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_505_2496_Open_Image onclick="this.style.display='none'; Codehighlighter1_505_2496_Open_Text.style.display='none'; Codehighlighter1_505_2496_Closed_Image.style.display='inline'; Codehighlighter1_505_2496_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_505_2496_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_505_2496_Closed_Text.style.display='none'; Codehighlighter1_505_2496_Open_Image.style.display='inline'; Codehighlighter1_505_2496_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;SpringContainer&nbsp;</SPAN><SPAN style="COLOR: #0000ff">implements</SPAN><SPAN style="COLOR: #000000">&nbsp;Container&nbsp;</SPAN><SPAN id=Codehighlighter1_505_2496_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_505_2496_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;ApplicationContext&nbsp;applicationContext;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_617_726_Open_Image onclick="this.style.display='none'; Codehighlighter1_617_726_Open_Text.style.display='none'; Codehighlighter1_617_726_Closed_Image.style.display='inline'; Codehighlighter1_617_726_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_617_726_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_617_726_Closed_Text.style.display='none'; Codehighlighter1_617_726_Open_Image.style.display='inline'; Codehighlighter1_617_726_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;SpringContainer(ServletContext&nbsp;servletContext)&nbsp;</SPAN><SPAN id=Codehighlighter1_617_726_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_617_726_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.applicationContext&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;WebApplicationContextUtils.getWebApplicationContext(servletContext);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_795_855_Open_Image onclick="this.style.display='none'; Codehighlighter1_795_855_Open_Text.style.display='none'; Codehighlighter1_795_855_Closed_Image.style.display='inline'; Codehighlighter1_795_855_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_795_855_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_795_855_Closed_Text.style.display='none'; Codehighlighter1_795_855_Open_Image.style.display='inline'; Codehighlighter1_795_855_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;SpringContainer(ApplicationContext&nbsp;applicationContext)&nbsp;</SPAN><SPAN id=Codehighlighter1_795_855_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_795_855_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.applicationContext&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;applicationContext;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_862_1012_Open_Image onclick="this.style.display='none'; Codehighlighter1_862_1012_Open_Text.style.display='none'; Codehighlighter1_862_1012_Closed_Image.style.display='inline'; Codehighlighter1_862_1012_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_862_1012_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_862_1012_Closed_Text.style.display='none'; Codehighlighter1_862_1012_Open_Image.style.display='inline'; Codehighlighter1_862_1012_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><SPAN id=Codehighlighter1_862_1012_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><FONT size=2>/**&nbsp;*/</FONT></SPAN><SPAN id=Codehighlighter1_862_1012_Open_Text><SPAN style="COLOR: #008000"><FONT size=2>/**</FONT></SPAN><SPAN style="COLOR: #008000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</FONT></SPAN><SPAN style="COLOR: #808080"><FONT size=2>@param</FONT></SPAN><FONT size=2><SPAN style="COLOR: #008000">&nbsp;key<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;component&nbsp;class&nbsp;type&nbsp;or&nbsp;component&nbsp;name<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</SPAN><SPAN style="COLOR: #808080">@return</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #808080">@throws</SPAN></FONT><SPAN style="COLOR: #008000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ComponentNotFoundException<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><SPAN style="COLOR: #008000"><FONT size=2>*/</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG id=Codehighlighter1_1091_2060_Open_Image onclick="this.style.display='none'; Codehighlighter1_1091_2060_Open_Text.style.display='none'; Codehighlighter1_1091_2060_Closed_Image.style.display='inline'; Codehighlighter1_1091_2060_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1091_2060_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1091_2060_Closed_Text.style.display='none'; Codehighlighter1_1091_2060_Open_Image.style.display='inline'; Codehighlighter1_1091_2060_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;Object&nbsp;getComponent(Object&nbsp;key)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;ComponentNotFoundException&nbsp;</SPAN><SPAN id=Codehighlighter1_1091_2060_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_1091_2060_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(applicationContext&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throw</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;IllegalStateException(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Spring&nbsp;Application&nbsp;context&nbsp;has&nbsp;not&nbsp;been&nbsp;set</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(key&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throw</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ComponentNotFoundException(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">The&nbsp;component&nbsp;key&nbsp;can&nbsp;not&nbsp;be&nbsp;null</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR><IMG id=Codehighlighter1_1371_1995_Open_Image onclick="this.style.display='none'; Codehighlighter1_1371_1995_Open_Text.style.display='none'; Codehighlighter1_1371_1995_Closed_Image.style.display='inline'; Codehighlighter1_1371_1995_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1371_1995_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1371_1995_Closed_Text.style.display='none'; Codehighlighter1_1371_1995_Open_Image.style.display='inline'; Codehighlighter1_1371_1995_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(key&nbsp;</SPAN><SPAN style="COLOR: #0000ff">instanceof</SPAN><SPAN style="COLOR: #000000">&nbsp;Class)&nbsp;</SPAN><SPAN id=Codehighlighter1_1371_1995_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_1371_1995_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;beans&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;applicationContext.getBeansOfType((Class)&nbsp;key);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(beans&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throw</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ComponentNotFoundException(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">The&nbsp;container&nbsp;is&nbsp;unable&nbsp;to&nbsp;resolve&nbsp;single&nbsp;instance&nbsp;of&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;((Class)&nbsp;key).getName()<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;none&nbsp;instances&nbsp;found</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(beans.size()&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">||</SPAN><SPAN style="COLOR: #000000">&nbsp;beans.size()&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throw</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ComponentNotFoundException(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">The&nbsp;container&nbsp;is&nbsp;unable&nbsp;to&nbsp;resolve&nbsp;single&nbsp;instance&nbsp;of&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;((Class)&nbsp;key).getName()<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;number&nbsp;of&nbsp;instances&nbsp;found&nbsp;was:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;beans.size());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;beans.keySet().iterator().next();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><SPAN style="COLOR: #0000ff"><FONT size=2>return</FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;applicationContext.getBean(key.toString());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_2088_2180_Open_Image onclick="this.style.display='none'; Codehighlighter1_2088_2180_Open_Text.style.display='none'; Codehighlighter1_2088_2180_Closed_Image.style.display='inline'; Codehighlighter1_2088_2180_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_2088_2180_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2088_2180_Closed_Text.style.display='none'; Codehighlighter1_2088_2180_Open_Image.style.display='inline'; Codehighlighter1_2088_2180_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;reload()&nbsp;</SPAN><SPAN id=Codehighlighter1_2088_2180_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_2088_2180_Open_Text><SPAN style="COLOR: #000000"><FONT size=2>{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((AbstractApplicationContext)&nbsp;applicationContext).refresh();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_2230_2393_Open_Image onclick="this.style.display='none'; Codehighlighter1_2230_2393_Open_Text.style.display='none'; Codehighlighter1_2230_2393_Closed_Image.style.display='inline'; Codehighlighter1_2230_2393_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_2230_2393_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2230_2393_Closed_Text.style.display='none'; Codehighlighter1_2230_2393_Open_Image.style.display='inline'; Codehighlighter1_2230_2393_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;autowireComponent(Object&nbsp;bean)&nbsp;</SPAN><SPAN id=Codehighlighter1_2230_2393_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_2230_2393_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((AbstractApplicationContext)&nbsp;applicationContext).getBeanFactory().autowireBeanProperties(bean,&nbsp;AutowireCapableBeanFactory.AUTOWIRE_BY_NAME,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_2420_2493_Open_Image onclick="this.style.display='none'; Codehighlighter1_2420_2493_Open_Text.style.display='none'; Codehighlighter1_2420_2493_Closed_Image.style.display='inline'; Codehighlighter1_2420_2493_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_2420_2493_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2420_2493_Closed_Text.style.display='none'; Codehighlighter1_2420_2493_Open_Image.style.display='inline'; Codehighlighter1_2420_2493_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;close()&nbsp;</SPAN><SPAN id=Codehighlighter1_2420_2493_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_2420_2493_Open_Text><SPAN style="COLOR: #000000"><FONT size=2>{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((AbstractApplicationContext)&nbsp;applicationContext).close();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</FONT></SPAN></SPAN></DIV><BR><FONT size=2>代码2：<BR></FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_206_574_Open_Image onclick="this.style.display='none'; Codehighlighter1_206_574_Open_Text.style.display='none'; Codehighlighter1_206_574_Closed_Image.style.display='inline'; Codehighlighter1_206_574_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_206_574_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_206_574_Closed_Text.style.display='none'; Codehighlighter1_206_574_Open_Image.style.display='inline'; Codehighlighter1_206_574_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;ComponentAutowireInterceptor&nbsp;</SPAN><SPAN style="COLOR: #0000ff">implements</SPAN><SPAN style="COLOR: #000000">&nbsp;Interceptor&nbsp;</SPAN><SPAN id=Codehighlighter1_206_574_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_206_574_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_236_285_Open_Image onclick="this.style.display='none'; Codehighlighter1_236_285_Open_Text.style.display='none'; Codehighlighter1_236_285_Closed_Image.style.display='inline'; Codehighlighter1_236_285_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_236_285_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_236_285_Closed_Text.style.display='none'; Codehighlighter1_236_285_Open_Image.style.display='inline'; Codehighlighter1_236_285_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;destroy()&nbsp;</SPAN><SPAN id=Codehighlighter1_236_285_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_236_285_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub</SPAN></FONT><SPAN style="COLOR: #008000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_311_360_Open_Image onclick="this.style.display='none'; Codehighlighter1_311_360_Open_Text.style.display='none'; Codehighlighter1_311_360_Closed_Image.style.display='inline'; Codehighlighter1_311_360_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_311_360_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_311_360_Closed_Text.style.display='none'; Codehighlighter1_311_360_Open_Image.style.display='inline'; Codehighlighter1_311_360_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;init()&nbsp;</SPAN><SPAN id=Codehighlighter1_311_360_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_311_360_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub</SPAN></FONT><SPAN style="COLOR: #008000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></FONT></SPAN><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_437_571_Open_Image onclick="this.style.display='none'; Codehighlighter1_437_571_Open_Text.style.display='none'; Codehighlighter1_437_571_Closed_Image.style.display='inline'; Codehighlighter1_437_571_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_437_571_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_437_571_Closed_Text.style.display='none'; Codehighlighter1_437_571_Open_Image.style.display='inline'; Codehighlighter1_437_571_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;intercept(ActionInvocation&nbsp;invocation)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;</SPAN><SPAN id=Codehighlighter1_437_571_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_437_571_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.getInstance().getContainer().autowireComponent(invocation.getAction());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN></FONT><SPAN style="COLOR: #000000"><FONT size=2>&nbsp;invocation.invoke();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</FONT></SPAN></SPAN><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></FONT></SPAN></DIV><BR><FONT size=2>这几段代码，你不需要在spring里配置action，也不需要在xwork.xml里面配置external-ref。只要保证action引用的东东和spring里面同名就能够auto wire by name了。<BR><BR>原理：拦截器会在每个action之前调用autowireComponent(invocation.getAction())。这样spring就会去自动组装这个传进来的action对象，而action对象里的属性和spring里的bean id同名。所以spring就会自动将application.xml里对应的bean注射到action的属性里去，从而达到把action按用户希望的方式组装起来的目的。<BR><BR>如：<BR>appliaction.xml<BR></FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">bean&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="myService"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="target"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">bean&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="myServiceDefaultImpl"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;autowire</SPAN><SPAN style="COLOR: #0000ff">="byName"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">property</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">bean</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></DIV><BR><FONT size=2>xwork.xml<BR></FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">action&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="myAction"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;class</SPAN><SPAN style="COLOR: #0000ff">="myAction"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">result&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="success"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/success.ftl</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">result</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">action</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></DIV><BR><FONT size=2>Action:<BR></FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></FONT><SPAN style="COLOR: #000000"><FONT size=2>public&nbsp;class&nbsp;myAction&nbsp;extends&nbsp;ActionSupport&nbsp;{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;myService;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.......<BR><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp; }<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></FONT></SPAN></DIV><BR><FONT size=2>最后记得要在web.xml配上listener-class</FONT><img src ="http://www.blogjava.net/lilan1983/aggbug/21119.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lilan1983/" target="_blank">李岚</a> 2005-11-23 13:52 <a href="http://www.blogjava.net/lilan1983/archive/2005/11/23/21119.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AOP,IOC,Spring</title><link>http://www.blogjava.net/lilan1983/archive/2005/06/01/5408.html</link><dc:creator>李岚</dc:creator><author>李岚</author><pubDate>Wed, 01 Jun 2005 06:11:00 GMT</pubDate><guid>http://www.blogjava.net/lilan1983/archive/2005/06/01/5408.html</guid><wfw:comment>http://www.blogjava.net/lilan1983/comments/5408.html</wfw:comment><comments>http://www.blogjava.net/lilan1983/archive/2005/06/01/5408.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lilan1983/comments/commentRss/5408.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lilan1983/services/trackbacks/5408.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 17pt 0cm 16.5pt"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">理解</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%">AOP<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></H1>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">我觉得面向对象很好地解决了软件系统中职责划分的问题<SPAN lang=EN-US>.借助于面向对象,软件开发人员一般的,都可以将需求里的名词转换成系统中的对象,动词转换为对象里的方法.这样非常符合人的思维方式,非常自然.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><BR>但是,问题是某些需求却偏偏不是能用这样的”名词”和”动词”就能完美的描述出来的,假如这样的问题:需要对系统中的某些方法进行事务处理,这种需要事务代码散布在多个类中.面对这种需求,应该怎么办呢?最直接的办法就是:创建一个基类(接口)或者一个助手,将事务处理的功能放在其中,并让所有需要事务功能的类继承这个基类(接口)或者使用这个助手.加入这样的.需要修改的地方就会分散在多个文件中.这样大的修改量,无疑会增加出错的几率,并且加大系统维护的难度,如图:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=120 alt=1.jpg src="http://www.blogjava.net/images/blogjava_net/lilan1983/aop)spring/1.jpg" width=199 border=0><BR></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 115.5pt; mso-char-indent-count: 11.0"><SPAN lang=EN-US><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><BR><BR><BR>因此,面向方面的编程(</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Aspect</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Oriented</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Programming</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">,</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">AOP</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">)应运而生.</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">AOP</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">为开发者提供了一种描述横切关注点的机制<SPAN lang=EN-US>,并能够自动将横切关注点织入到面向对象的软件系统中，从而实现了横切关注点的模块化.通过划分</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Aspect</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">代码<SPAN lang=EN-US>,横切关注点变得容易处理.开发者可以在编译时更改,插入或除去系统的</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Aspect</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">,甚至重用系统的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Aspect</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">.” </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">OOP</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">只用于表示对象之间的泛化<SPAN lang=EN-US>-特化(</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">generalization</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">-</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">specialization</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">)关系(通过继承来表现),而对象之间的横向关联则完全用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">AOP</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">来表现<SPAN lang=EN-US>. 这样,很多给对象之间横向关联增加灵活性的设计模式(例如</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Decorator</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">等<SPAN lang=EN-US>)将不再必要.”,如图:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG style="WIDTH: 206px; HEIGHT: 166px" height=170 alt=2.jpg src="http://www.blogjava.net/images/blogjava_net/lilan1983/aop)spring/2.jpg" width=206 border=0><BR><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 115.5pt; mso-char-indent-count: 11.0"><SPAN lang=EN-US></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P>
<H1 style="MARGIN: 17pt 0cm 16.5pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%">Spring</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%; FONT-FAMILY: 宋体">中的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%">Ioc</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></H1>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">想一想以前在使用工厂模式的时候<SPAN lang=EN-US>,在最早的情况下,每个工厂可能都是一个</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Singleton,</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">生成对象的代码被写死在了类里面<SPAN lang=EN-US>.后来人们觉这样还是耦合程度太高,还不够灵活.所以把对象的类名写在一个</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">XML</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">文件里<SPAN lang=EN-US>,这样一来.问题又来了,每个工厂都有自己的读取配置文件的代码,通过读取XML文件,或者通过读取Properties,工厂里充满了乱糟糟的和业务逻辑完全不相关的配置管理代码,维护起来很不方便,.而</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Spring</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">通过</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">”</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件工厂</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">”</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">把这些都集成在了一起<SPAN lang=EN-US>,用一个统一的</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">BeanFactory</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">来管理这些配置<SPAN lang=EN-US>,而且提供了更高一级的抽象:</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">ApplicationContext</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt">Ioc</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">好像很神奇的样子<SPAN lang=EN-US>,其实原理和实现都很简单,就是将要使用的对象都用XML来定义,用反射来生成,用注射的方式来使用. 其实</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Ioc</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">是工厂模式的升华，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Ioc</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">可以被看作是一个大工厂，只不过这个大工厂里要生成的对象都是在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">XML</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">文件中给出定义的，然后利用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Java</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">的<SPAN lang=EN-US>“反射”编程，根据</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">XML</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">中给出的类名生成相应的对象。从实现来看，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Ioc</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">是把以前在工厂方法里写死的对象生成代码，改变为由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">XML</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">文件来定义，也就是把工厂和对象生成这两者独立分隔开来，目的就是提高灵活性和可维护性。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<H1 style="MARGIN: 17pt 0cm 16.5pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%">Template Method</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 240%; FONT-FAMILY: 宋体">和回调在框架中的使用<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></H1>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt">Template</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">模式主要是用来解决这样的一个问题<SPAN lang=EN-US>:当你知道算法的具体步骤,但不知道如何去执行这些步骤.</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt">Template</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">把如何执行这些步骤的方法都封装成抽象的函数<SPAN lang=EN-US>,并且提供一个正确的顺序去执行这些步骤,而具体子类实现这些处理各个步骤的抽象方法.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">业务逻辑抽象到超类集中化就是所谓的<SPAN lang=EN-US>”控制反转”了.在传统的类库中,一般是由客户端来调用类库里的方法.而在这里,却是框架控制了用户流程,具体的子类只是要求履行一个明确的契约.在Spring中的MVC框架里,jdbc包里.都大量的使用了Template模式.</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体">而<SPAN lang=EN-US>Java中的回调函数主要是在实现事件驱动模型的时候使用的,但是在Spring里面,回调被赋予了新的意义:通过回调接口(函数)来实现可扩展性.如jdbc包的RowcallbackHandler.<o:p></o:p></SPAN></SPAN></P><img src ="http://www.blogjava.net/lilan1983/aggbug/5408.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lilan1983/" target="_blank">李岚</a> 2005-06-01 14:11 <a href="http://www.blogjava.net/lilan1983/archive/2005/06/01/5408.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对Spring MVC Framework的理解</title><link>http://www.blogjava.net/lilan1983/archive/2005/05/27/5258.html</link><dc:creator>李岚</dc:creator><author>李岚</author><pubDate>Fri, 27 May 2005 03:29:00 GMT</pubDate><guid>http://www.blogjava.net/lilan1983/archive/2005/05/27/5258.html</guid><wfw:comment>http://www.blogjava.net/lilan1983/comments/5258.html</wfw:comment><comments>http://www.blogjava.net/lilan1983/archive/2005/05/27/5258.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/lilan1983/comments/commentRss/5258.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lilan1983/services/trackbacks/5258.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 前言最近在看Spring MVC的源码,就把自己对MVC模式和对各种框架的实现的认识写出来给大家看看,算是一个总结.所以,恳请大家用怀疑的眼光来看待这篇文章,假如有认识不对的地方,麻烦指出.MVC与WEB应用MVC是什么就不用我多说了.对于现有较成熟的Model-View-Control(MVC)框架而言,其注意的主要问题无外乎下面这些:Model:模型应该包含由视图显示的数据...&nbsp;&nbsp;<a href='http://www.blogjava.net/lilan1983/archive/2005/05/27/5258.html'>阅读全文</a><img src ="http://www.blogjava.net/lilan1983/aggbug/5258.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lilan1983/" target="_blank">李岚</a> 2005-05-27 11:29 <a href="http://www.blogjava.net/lilan1983/archive/2005/05/27/5258.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>