﻿<?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-即兴的灵感-随笔分类-Spring</title><link>http://www.blogjava.net/improviser/category/26126.html</link><description>思维是一种艺术，艺术需要灵感</description><language>zh-cn</language><lastBuildDate>Mon, 05 Nov 2007 04:13:20 GMT</lastBuildDate><pubDate>Mon, 05 Nov 2007 04:13:20 GMT</pubDate><ttl>60</ttl><item><title>偶遇Spring MVC</title><link>http://www.blogjava.net/improviser/archive/2007/11/04/158025.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Sun, 04 Nov 2007 02:44:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/11/04/158025.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/158025.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/11/04/158025.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/158025.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/158025.html</trackback:ping><description><![CDATA[
		<font color="#0000ff" size="4">    个人认为Spring其核心是其IOC和AOP方面，对其SpirngMVC框架并不关注，我看好的是JSF，简单易懂。但最近由于工作上需要，所以有需要对SpringMVC做个了解学习，因此，本次对SpirngMVC的相遇纯属偶遇....<br />    SpingMVC的架构其实也很简单，它通过一个共通的入门DispatcherServlet来接收所有的request，接下来根据request要求的页面通过handler转送给Controller处理，处理结果返回View给用户，因此对SpringMVC来说，其核心为DispatcherServlet。<br />    DispatcherServlet作为一扇门，我们要使用这个门，首先得安装上这个门，安装在哪呢？没错，就安装在web.xml这个大屋子，象其他servlet一样，<span class="javascript" id="text151213">描述servlet的名字和类，再给他一个mapping描述对应映射的网页。在下例中，</span><span class="javascript" id="text151213">我们给DispatcherServlet的起名为</span><font color="#000080"><span class="javascript" id="text151213"><span style="color: rgb(0, 0, 0);"><font color="#0000ff">SpringMVCDemo，</font></span></span></font><span class="javascript" id="text151213">并让container知道所有.do结尾的request都丟给dispatcher。</span></font>
		<span class="javascript" id="text151213">
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 0, 0);">    </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">servlet</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">servlet-name</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">SpringMVCDemo</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">servlet-name</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">servlet-class</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />            org.springframework.web.servlet.DispatcherServlet<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">servlet-class</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">load-on-startup</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">1</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">load-on-startup</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">servlet</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">servlet-mapping</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">servlet-name</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">SpringMVCDemo</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">servlet-name</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">url-pattern</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">*.do</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">url-pattern</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">servlet-mapping</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
				</div>
				<font color="#0000ff">   <font size="4"> 门安装好了之后，我们需要定义门能打开的范围，在哪定义呢？就在门的上面贴上一张“入门指导”，介绍从哪方面(hello.do)进门需要使用何种交通方式(springmvcController)进去，并定义该交通方式。</font></font>
				<br />
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 0, 0);">    </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">bean </span>
						<span style="color: rgb(255, 0, 0);">id</span>
						<span style="color: rgb(0, 0, 255);">="urlMapping"</span>
						<span style="color: rgb(255, 0, 0);">
								<br />        class</span>
						<span style="color: rgb(0, 0, 255);">="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">property </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="mappings"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />            </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">props</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />                </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">prop </span>
						<span style="color: rgb(255, 0, 0);">key</span>
						<span style="color: rgb(0, 0, 255);">="/hello.do"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">springmvcController</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">prop</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />            </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">props</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">property</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">bean</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />    </span>
						<span style="color: rgb(0, 128, 0);">&lt;!--</span>
						<span style="color: rgb(0, 128, 0);"> SpringmvcController </span>
						<span style="color: rgb(0, 128, 0);">--&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">bean </span>
						<span style="color: rgb(255, 0, 0);">id</span>
						<span style="color: rgb(0, 0, 255);">="springmvcController"</span>
						<span style="color: rgb(255, 0, 0);">
								<br />        class</span>
						<span style="color: rgb(0, 0, 255);">="org.improviser.webapp.controller.SpringmvcController"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">bean</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
				</div>    <font color="#0000ff" size="4">接下来该渲染一下页面了，下面为渲染所有以</font></span>
		<font color="#000080" size="4">
				<span class="javascript" id="text151213">
						<span style="color: rgb(0, 0, 0);">
								<font color="#0000ff">WEB-INF/pages/</font>
								<font color="#0000ff">开头</font>，<font color="#0000ff">并以.</font><font color="#0000ff">jsp结尾的页面。</font></span>
				</span>
		</font>
		<span class="javascript" id="text151213">
				<br />
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 0, 0);">    </span>
						<span style="color: rgb(0, 128, 0);">&lt;!--</span>
						<span style="color: rgb(0, 128, 0);"> ViewSolver </span>
						<span style="color: rgb(0, 128, 0);">--&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">bean </span>
						<span style="color: rgb(255, 0, 0);">id</span>
						<span style="color: rgb(0, 0, 255);">="viewResolver"</span>
						<span style="color: rgb(255, 0, 0);">
								<br />        class</span>
						<span style="color: rgb(0, 0, 255);">="org.springframework.web.servlet.view.InternalResourceViewResolver"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">property </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="viewClass"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />            </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">value</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">org.springframework.web.servlet.view.JstlView</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">value</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">property</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">property </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="prefix"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />            </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">value</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">/WEB-INF/pages/</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">value</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">property</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">property </span>
						<span style="color: rgb(255, 0, 0);">name</span>
						<span style="color: rgb(0, 0, 255);">="suffix"</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />            </span>
						<span style="color: rgb(0, 0, 255);">&lt;</span>
						<span style="color: rgb(128, 0, 0);">value</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">.jsp</span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">value</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">property</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 255);">&lt;/</span>
						<span style="color: rgb(128, 0, 0);">bean</span>
						<span style="color: rgb(0, 0, 255);">&gt;</span>
				</div>   <font size="4"></font><font color="#0000ff" size="4">上面提到的SpringmvcController，</font><font color="#0000ff" size="4">现在该作个定义了，该类需要实现Controller</font><font color="#0000ff" size="4">接口。</font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> SpringmvcController </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> Controller {<br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> Logger for this class and subclasses </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> Log logger </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> LogFactory.getLog(getClass());<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> ModelAndView handleRequest(HttpServletRequest request,<br />            HttpServletResponse response) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> ServletException, IOException {</span><span style="color: rgb(0, 0, 0);"><br /><br />        Map model </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashMap();<br /><br />        String str </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">即兴诗人</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />        logger.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">returning hello view with </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> currTime);</span><span style="color: rgb(0, 0, 0);"><br />        model.put(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">coldice</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, str);<br /><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ModelAndView(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">hello</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">message</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, model);<br />    }</span></div>   <font color="#0000ff"><font size="4">编写jsp</font></font><font color="#0000ff" size="4">测试页面。</font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Spring Application</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">h1</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">br </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />            Hello <br /></span><span class="javascript" id="text151213"><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">            &lt;</span><span style="color: rgb(128, 0, 0);">c:out </span><span style="color: rgb(255, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">="${message.coldice}"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;&lt;/br&gt;</span></span><br /><span style="color: rgb(0, 0, 0);">            Spring MVC 测试成功！<br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">h1</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><font color="#000000"><span class="javascript" id="text151213"><span style="color: rgb(0, 0, 255);"></span></span></font><span class="javascript" id="text151213"></span></div>  <b>  <font color="#000080" size="4">现在对以上内容作个总结，正如上面所叙述，SpringMVC框架的处理过程机制如下图所示，接收请求页面，通过DispatcherServlet映射到相应规则处理，并找到相应的控制器，结果控制器处理后返回相应的页面最后返回给用户。</font></b><br /><img src="http://www.blogjava.net/images/blogjava_net/improviser/138199405_8b54d56b71_o.png" alt="138199405_8b54d56b71_o.png" border="0" height="387" width="732" /><br /><br /></span>
<img src ="http://www.blogjava.net/improviser/aggbug/158025.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-11-04 10:44 <a href="http://www.blogjava.net/improviser/archive/2007/11/04/158025.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之十（Spring研读总结）</title><link>http://www.blogjava.net/improviser/archive/2007/09/29/149474.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Sat, 29 Sep 2007 02:07:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/29/149474.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/149474.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/29/149474.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/149474.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/149474.html</trackback:ping><description><![CDATA[
		<font color="#0000ff">    </font>
		<font color="#0000ff" size="4">通过这几天对Spring的研读，剖析了Spring的基本核心模块——IoC和AOP。今天将对其作个基础性的总结。<br /><br />     Spring 是一个开源框架，是为了解决企业应用程序开发复杂性而创建的。框架的主要优势之一就是其分层架构，分层架构允许您选择使用哪一个组件，模块构建在核心容器之上，核心容器定义了创建、配置和管理 bean 的方式,同时为 J2EE 应用程序开发提供集成的框架。其中作为Spring的核心模块即是Spring面向方面编程(AOP)和控制反转(IOC)容器。Spring 设计的核心是 <code>org.springframework.beans</code> 包，<code>BeanFactory</code><code>BeanFactory</code> 支持两个对象模型单态和原型。<code>BeanFactory</code>是Spring作为IOC 容器的基础。<br /><br />    控制反转模式：不创建对象，但是描述创建它们的方式。在代码中不直接与对象和服务连接，但在配置文件中描述哪一个组件需要哪一项服务。容器（在 Spring 框架中是 IOC 容器）负责将这些联系在一起。在典型的 IOC 场景中，容器创建了所有对象，并设置必要的属性将它们连接在一起，决定什么时间调用方法。IOC 的一个实现模式:通过接口、通过 JavaBean 的属性、依赖性以构造函数的形式提供。<br /><br />    面向方面的编程，即 AOP，是一种编程技术，它允许程序员对横切关注点或横切典型的职责分界线的行为（例如日志和事务管理）进行模块化。AOP 的核心构造是方面，它将那些影响多个类的行为封装到可重用的模块中。AOP 和 IOC 是补充性的技术，它们都运用模块化方式解决企业应用程序开发中的复杂问题。在典型的面向对象开发方式中，可能要将日志记录语句放在所有方法和 Java 类中才能实现日志功能。在 AOP 方式中，可以反过来将日志服务模块化，并以声明的方式将它们应用到需要日志的组件上。当然，优势就是 Java 类不需要知道日志服务的存在，也不需要考虑相关的代码。所以，用 Spring AOP 编写的应用程序代码是松散耦合的。AOP 的功能完全集成到了 Spring 事务管理、日志和其他各种特性的上下文中。</font>
<img src ="http://www.blogjava.net/improviser/aggbug/149474.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-29 10:07 <a href="http://www.blogjava.net/improviser/archive/2007/09/29/149474.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之九（AOP in Spring）</title><link>http://www.blogjava.net/improviser/archive/2007/09/29/149406.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Fri, 28 Sep 2007 17:50:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/29/149406.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/149406.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/29/149406.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/149406.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/149406.html</trackback:ping><description><![CDATA[    <font size="4"><font color="#0000ff">Spring IoC和 Spring
AOP组合，一起形成了Spring，这样一个有机整体，使得构建轻量级的J2EE架构成为可能，而且事实证明，非常有效。没有Spring
IoC的Spring AOP是不完善的，没有Spring AOP的Spring IoC是不健壮的。 本文研究Spring框架中的面向方面编(Aspect-Oriented Programming，AOP)，进而通过例子解析如何运用Spring中的所有通知类型和切入点来实现更实用的方面和面向方面设计模式。</font><br /><br />    <b><font color="#000080">AOP概念：</font></b><br />    <font color="#000080"><b>Advice：</b></font><font color="#0000ff">如何将before通知、afterReturning通知和afterThrowing通知声明为bean。</font><br />　<font color="#000080"><b>Pointcut</b></font><b>：</b><font color="#0000ff">如何声明静态切入点逻辑以将XML Spring Bean Configuration文件中的所有内容联系在一起。 </font><br />　<font color="#000080"><b>Advisor：</b></font><font color="#0000ff">关联切入点定义与通知bean的方式。</font><br /><br /><span style="font-size: 12pt; font-family: 宋体;" lang="EN-US">    <font color="#0000ff">Spring AOP</font></span><font color="#0000ff"><span style="font-size: 12pt; font-family: 宋体;">是使用代理来完成的，<span lang="EN-US">Spring </span>两种方式：<span lang="EN-US"></span><span lang="EN-US">JDK</span>动态代理，需要设定一组代理接口；<span lang="EN-US"></span><span lang="EN-US">CGLIB </span>代理，可代理接口和类。<span lang="EN-US"></span><span lang="EN-US"></span><span lang="EN-US"></span></span>Spring提供了5种Advice类型：Interception Around、Before、After
Returning、Throw和Introduction。它们分别在以下情况下被调用：在JointPoint前后、JointPoint前、
JointPoint后、JointPoint抛出异常时、JointPoint调用完毕后。<br /></font><br /><font color="#800080"><b>配置文件：</b></font></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="myAOPProxy"</span><span style="color: rgb(255, 0, 0);"><br />             class</span><span style="color: rgb(0, 0, 255);">="org.springframework.aop.framework.ProxyFactoryBean"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="proxyInterfaces"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">ITest</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="target"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">local </span><span style="color: rgb(0, 0, 255);">= "test"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="interceptorNames"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">myPotincutAdvisor</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="Test"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="MyInterceptor"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="MethodTimeCostInterceptor"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="myPotincutAdvisor"</span><span style="color: rgb(255, 0, 0);"><br />             class</span><span style="color: rgb(0, 0, 255);">="org.springframework.aop.support.RegexpMethodPointcutAdvisor"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="advice"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">local</span><span style="color: rgb(0, 0, 255);">="MyInterceptor"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="patterns"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">.*</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">.*</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /><font size="4"><b><font color="#800080">分析代码：</font></b><br /><font color="#0000ff">1</font>、<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="myAOPProxy"</span><span style="color: rgb(255, 0, 0);"><br />     class</span><span style="color: rgb(0, 0, 255);">="org.springframework.aop.framework.ProxyFactoryBean"</span><span style="color: rgb(0, 0, 255);">&gt;声明注入了代理实例myAOPProxy</span><span style="color: rgb(0, 0, 255);">。        <br />2、 proxyInterfaces声明将被代理接口ITest。</span><br /><span style="color: rgb(0, 0, 255);">3、 target声明被代理目的类。<br /></span><font color="#0000ff">4</font>、 <span style="color: rgb(0, 0, 255);">interceptorNames设置拦截器为</span><span style="color: rgb(0, 0, 255);"></span><font color="#330000"><span style="color: rgb(0, 0, 0);">myPotincutAdvisor</span></font><span style="color: rgb(0, 0, 255);">。<br />5、 </span></font><span style="color: rgb(0, 0, 255);"><font size="4">patterns为拦截器设置配匹方式，即在所被配匹成功的方法被调用时执行拦截器内容。</font><br /><font size="4"><br /></font></span><font size="4">    </font><font color="#993300"><font size="4">该配置文件，指定要加载一个接口与ITest相匹配的bean。该bean随后被关联到Test实现类。看起来好像是费了很大力气只为了加载一个简单的bean并调用一个方法，但是这个配置文件只是使
Spring框架可以透明地对应用程序应用其组件的众多特性的一个体现</font>。</font><br /><img src ="http://www.blogjava.net/improviser/aggbug/149406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-29 01:50 <a href="http://www.blogjava.net/improviser/archive/2007/09/29/149406.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之八（Internationalization of spring）</title><link>http://www.blogjava.net/improviser/archive/2007/09/27/148476.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Wed, 26 Sep 2007 17:00:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/27/148476.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/148476.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/27/148476.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/148476.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/148476.html</trackback:ping><description><![CDATA[
		<font size="4">
				<span style="font-size: 10.5pt; font-family: 宋体;">
						<font size="4">    <font color="#cc0000" size="4">国际化支持在实际开发中可能是最常用的特性，本文分析Spring的</font></font>
						<font size="4">
						</font>
				</span>
				<font color="#cc0000" size="4">
						<span style="font-family: 宋体;" lang="EN-US">ApplicationContext</span>
				</font>
		</font>
		<font color="#cc0000" size="4">
				<span style="font-family: 宋体;">提供国际化支持，</span>
				<span style="font-family: 宋体;">其提供了更加强大的功能，如信息的自动装配以及热部署功能（配置文件修改后自动读取，而无需重新启动应用程序）。<span lang="EN-US"><o:p></o:p></span></span>
		</font>
		<span style="font-family: 宋体;">
				<font color="#cc0000" size="4">
						<br />    目前<span lang="EN-US">Spring</span>中提供了两个<span lang="EN-US"> MessageSource</span>接口的实现，即<span lang="EN-US">ResourceBundleMessageSource</span>和<span lang="EN-US">ReloadableResourceBundleMessageSource</span>，后者提供了无需重启即可重新加载配置信息的特性。</font>
				<font size="5">
				</font>
				<br />
		</span>
		<span style="font-family: 宋体;">    <br />   <font color="#666600" size="4"> 在下面的配置文件中，通过<span lang="EN-US">MessageResource</span>的一个实现类<span lang="EN-US">org.springframework.context.support.ResourceBundleMessageSource</span>来获得国际化的信息。</font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">description</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Spring Quick Start</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">description</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="messageSource"</span><span style="color: rgb(255, 0, 0);"><br />     class</span><span style="color: rgb(0, 0, 255);">="org.springframework.context.support.ResourceBundleMessageSource"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="basenames"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">messages</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);"></span></div><br /></span>
		<p class="MsoNormal" style="text-indent: 21pt;">
				<font color="#006600" size="4">
						<span style="font-family: 宋体;">这里声明了一个名为</span>
						<b style="">
								<span style="font-family: 宋体;" lang="EN-US">messageSource</span>
						</b>
						<span style="font-family: 宋体;">的<span lang="EN-US">Bean</span>（</span>
						<b style="">
								<span style="font-family: 宋体;">注意：</span>
						</b>
				</font>
				<font color="#006600">
						<span style="font-family: 宋体;">
								<font size="4">对于<span lang="EN-US">Message</span>定义，<span lang="EN-US">Bean ID</span>必须为<span lang="EN-US">messageSource</span>，这是目前<span lang="EN-US">Spring</span>的编码规约），对应类为<span lang="EN-US">ResourceBundleMessageSource</span>。</font>
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</span>
				</font>
		</p>
		<p class="MsoNormal" style="text-indent: 21pt;">
				<span style="font-family: 宋体;">
						<font color="#663300" size="4">而其中的<span lang="EN-US">basename</span>属性用來设定资源信息文件的前置文件名称，在本例中为<span lang="EN-US">messages</span>。<span lang="EN-US">Spring</span>会自动在<span lang="EN-US">CLASSPATH</span>根路径中按照如下顺序搜寻资源信息文件并进行加载（以<span lang="EN-US">Locale</span>为<span lang="EN-US">zh_CN</span>为例，其实<span lang="EN-US">Spring</span>在实际上调用了<span lang="EN-US">JDK</span>的<span lang="EN-US">ResourceBundle</span>读取配置文件）</font>
						<span lang="EN-US">
								<font color="#339900" size="4">:</font>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt;">
				<font color="#333300" size="4">
						<span style="font-family: 宋体;" lang="EN-US">messages_zh_CN.properties<o:p></o:p></span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt;">
				<font color="#333300" size="4">
						<span style="font-family: 宋体;" lang="EN-US">messages_zh.properties<o:p></o:p></span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt;">
				<font color="#333300" size="4">
						<span style="font-family: 宋体;" lang="EN-US">messages.properties<o:p></o:p></span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt;">
				<font color="#333300" size="4">
						<span style="position: relative; z-index: 1;">
						</span>
						<span style="font-family: 宋体;" lang="EN-US">messages_zh_CN.class<o:p></o:p></span>
				</font>
				<!--[endif]-->
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt;">
				<font color="#333300" size="4">
						<span style="font-family: 宋体;" lang="EN-US">messages_zh.class<o:p></o:p></span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt;">
				<font color="#333300" size="4">
						<span style="font-family: 宋体;" lang="EN-US">messages.class</span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<font color="#330000" size="4">
						<span style="font-family: 宋体;">资源配置信息文件中的内容</span>
				</font>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="3">
						<span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 0);">messages_zh_CN.properties：<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">userinfo</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">当前登录用户: </span><span style="color: rgb(128, 0, 0); font-weight: bold;">[</span><span style="color: rgb(128, 0, 0);">{0}</span><span style="color: rgb(128, 0, 0); font-weight: bold;">]</span><span style="color: rgb(0, 0, 0);"> 登录时间:</span><span style="color: rgb(128, 0, 0); font-weight: bold;">[</span><span style="color: rgb(128, 0, 0);">{1}</span><span style="color: rgb(128, 0, 0); font-weight: bold;">]</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">messages_en_US.properties：<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">userinfo</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Current Login user: </span><span style="color: rgb(128, 0, 0); font-weight: bold;">[</span><span style="color: rgb(128, 0, 0);">{0}</span><span style="color: rgb(128, 0, 0); font-weight: bold;">]</span><span style="color: rgb(0, 0, 0);"> Login time:</span><span style="color: rgb(128, 0, 0); font-weight: bold;">[</span><span style="color: rgb(128, 0, 0);">{1}</span><span style="color: rgb(128, 0, 0); font-weight: bold;">]</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">5</span> </font>
				<span style="color: rgb(0, 0, 0);">
				</span>
		</div>
		<br />  <b><font color="#333300">测试代码：</font></b><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font size="3"><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 0);">ApplicationContext ctx</span><span style="color: rgb(0, 0, 0);"> = <br />                </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemXmlApplicationContext(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bean.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">Object[] arg </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">{ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Erica</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, Calendar.getInstance().getTime()<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">};<br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">以系统默认Locale加载信息(对于中文WinXP而言，默认为zh_CN)</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">String msg </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ctx.getMessage(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">userinfo</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, arg);<br /></span><span style="color: rgb(0, 128, 128);">7</span> <span style="color: rgb(0, 0, 0);">System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Message is ===&gt; </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">msg);<br /></span><span style="color: rgb(0, 128, 128);">8</span> </font><span style="color: rgb(0, 0, 0);"></span></div><br /><p class="MsoNormal" style="text-indent: 21pt;"><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;" lang="EN-US">代码中，我们将一个<span lang="EN-US">Object</span>数组<span lang="EN-US">arg</span>作为参数传递给<span lang="EN-US">ApplicationContext.getMessage</span>方法，这个参数中包含了出现在最终文字信息中的可变内容，<span lang="EN-US">ApplicationContext</span>  将根据参数中的<span lang="EN-US">Locale</span>信息对其进行处理（如针对不同<span lang="EN-US">   Locale</span>设定日期输出格式），并用其替换配置文件中的<span lang="EN-US">{n}</span>标识（<span lang="EN-US">n</span>代表参数数组中的索引，从<span lang="EN-US">1  </span>开始）。<span lang="EN-US"><o:p></o:p></span><br /></span></font></p><p class="MsoNormal" style="text-indent: 21pt;"><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;" lang="EN-US">运行上面的代码，得到以下输出的内容：<span lang="EN-US"><o:p></o:p></span><br />   Message
is ===&gt; |</span></font><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;">ì〃¤<span lang="EN-US">?</span>°<span lang="EN-US">|</span>ì<span lang="EN-US">???</span>¨<span lang="EN-US">???</span>〃<span lang="EN-US">: [Erica] |</span>ì<span lang="EN-US">???</span>¨<span lang="EN-US">o</span>〃¤<span lang="EN-US">??:[07-9-27 </span>上午1<span lang="EN-US">:27]</span></span></font></p><p class="MsoNormal" style="text-indent: 21pt;"><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;" lang="EN-US">针对<span lang="EN-US">ResourceBundle</span>的编码过程中发生的问题。这是由于转码过程中产生的编码问题引发的。比较简单的解决办法是通过<span lang="EN-US">JDK</span>提供的转码工具<span lang="EN-US">native2ascii.exe</span>  进行转换。执行：<span lang="EN-US"><o:p></o:p></span>native2ascii
messages_zh_CN.properties msg.txt。<o:p></o:p></span></font><font color="#996600" face="Georgia" size="4">再用<span lang="EN-US">msg.txt</span>文件替换<span lang="EN-US">Messages_zh_CN.properties</span>       文件。</font><font face="Georgia"><br /></font></p><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;">   再次运行示例代码，得到正确输出：<span lang="EN-US"><o:p></o:p></span></span></font><p class="MsoNormal"><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;" lang="EN-US">   Message is ===&gt; </span><span style="font-family: 宋体;">当前登录用户<span lang="EN-US">: [Erica] </span>登录时间<span lang="EN-US">:[07-9-27 </span>上午<span lang="EN-US">1:30]<o:p></o:p></span></span></font></p><p class="MsoNormal" style="text-indent: 21pt;"><font color="#996600" face="Georgia" size="4"><span style="font-family: 宋体;">尝试在代码中指定不同的<span lang="EN-US">Locale</span>参数：<span lang="EN-US"><o:p></o:p></span></span></font></p><p class="MsoNormal" style="text-indent: 21pt;"><font color="#996600" face="Times New Roman" size="4"><span style="font-family: 宋体;"><font face="Georgia">String
msg = ctx.getMessage("userinfo", arg, Locale.US);<o:p></o:p>再次运行，可以看到：</font><span lang="EN-US"><o:p></o:p></span></span></font></p><p class="MsoNormal" style="text-indent: 21pt;"><font color="#996600" face="Times New Roman" size="4"><span style="font-family: 宋体;" lang="EN-US">Message
is ===&gt; Current Login user: [Erica] Login time::[9/27/07 1:35AM]</span></font></p><p class="MsoNormal" style="text-indent: 21pt;"><b><font color="#663300" face="Times New Roman" size="4"><span style="font-family: 宋体;">可见，前者根据当前默认<span lang="EN-US">Locale"zh_CN"</span>，<span lang="EN-US">getMessage</span>方法自动加载了<span lang="EN-US">messages_zh_CN.properties</span>文件；后者</span><font face="Georgia"><span style="font-size: 10.5pt; font-family: 宋体;" lang="EN-US">getMessage</span><span style="font-size: 10.5pt; font-family: 宋体;">方法根据指定编码<span lang="EN-US">"en_US"</span>加载了<span lang="EN-US">messages_en_US.properties</span>文件。</span></font></font></b></p><font color="#996600" face="Times New Roman" size="4"><br /><span style="font-family: 宋体;"><br /><span lang="EN-US"><o:p></o:p></span></span></font><p class="MsoNormal" style="text-indent: 21pt;"><span style="font-family: 宋体;"><br /><span lang="EN-US"><o:p></o:p></span></span></p><b style=""><span style="font-family: 宋体;"><span lang="EN-US"><o:p></o:p></span></span></b><img src ="http://www.blogjava.net/improviser/aggbug/148476.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-27 01:00 <a href="http://www.blogjava.net/improviser/archive/2007/09/27/148476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之七（Types of Injection）</title><link>http://www.blogjava.net/improviser/archive/2007/09/26/148472.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Wed, 26 Sep 2007 15:59:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/26/148472.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/148472.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/26/148472.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/148472.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/148472.html</trackback:ping><description><![CDATA[
		<p>
				<b>本文研究Spring的三种依赖注入实现类型</b>——<b style=""><span style="font-size: 10.5pt; font-family: 宋体;">接口注入（<span lang="EN-US">Interface Injection</span>）、</span></b><b style=""><span style="font-size: 10.5pt; font-family: 宋体;">设值注入（<span lang="EN-US">Setter Injection</span>）、</span></b><b style=""><span style="font-size: 10.5pt; font-family: 宋体;">构造子注入（<span lang="EN-US">Constructor Injection</span>）。</span></b></p>
		<p>
				<b style="">
						<span style="font-size: 10.5pt; font-family: 宋体;" lang="EN-US">Type1 </span>
						<span style="font-size: 10.5pt; font-family: 宋体;">接口注入：</span>
				</b>
				<font color="#663300" size="2">
						<span style="font-size: 10.5pt; font-family: 宋体;">传统的创建接口对象的方法，</span>
				</font>
				<font color="#663300">
						<span style="font-size: 10.5pt; font-family: 宋体;">借助接口来将调用者与实现者分离。如下面的代码所示：</span>
				</font>
		</p>
		<p>
				<span style="font-size: 10.5pt; font-family: 宋体;">
						<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
								<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
								<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ClassA <br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> InterfaceB clzB;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> doSomething() <br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">Ojbect obj </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Class.forName(Config.BImplementation).newInstance();<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">clzB </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (InterfaceB)obj;<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">clzB.doIt();<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">……<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);"></span></div>
						<br />
				</span>
		</p>
		<p>
				<span style="font-size: 10.5pt; font-family: 宋体;">
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 21pt;">
				<font color="#33cc00" size="4">
						<span style="font-family: 宋体;">在代码中创建<span lang="EN-US">InterfaceB</span>实现类的实例，并将该对象赋予<span lang="EN-US">clzB</span>。也就是依据<span lang="EN-US">Java</span>中的对象动态多态技术：<span lang="EN-US"><o:p></o:p></span>InterfaceB
clzB=new InterfaceBImpleClass();为了将调用者与实现者在编译期分离，于是有了上面的代码，我们根据预先在配置文件中设定的实现类的类名<span lang="EN-US">(Config.BImplementation)</span>，动态<span lang="EN-US"><o:p></o:p></span>加载实现类，并通过<span lang="EN-US">InterfaceB</span>强制转型后为<span lang="EN-US"> ClassA</span>所用。</span>
				</font>
		</p>
		<p class="MsoNormal" style="text-indent: 21pt;">
		</p>
		<p class="MsoNormal" style="text-indent: 21pt;">
				<span style="font-family: 宋体;">
				</span>
				<br />
				<b style="">
						<span style="font-size: 10.5pt; font-family: 宋体;" lang="EN-US">
								<br />Type2 </span>
						<span style="font-size: 10.5pt; font-family: 宋体;">设值注入：</span>
				</b>
				<font color="#663300" size="3">
						<span style="font-family: 宋体;">在各种类型的依赖注入模式中，设值注入模式在实际开发中得到了最广泛的应用（其中很大一部分得力于<span lang="EN-US">Spring</span>框架的</span>
				</font>
				<font color="#663300">
						<br />
				</font>
				<span style="font-family: 宋体;">
						<font color="#663300" size="3">影响）。<span lang="EN-US"><o:p></o:p></span>使用<span lang="EN-US">IoC</span>的<span lang="EN-US">Setter</span>注射，一些外部元数据被用于解决依赖性问题。并且在<span lang="EN-US">Spring</span>中，这种元数据采取了简单的<span lang="EN-US">XML</span>配置文件的形式。</font>
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</span>
				<br />
				<b style="">
						<span style="font-family: 宋体;">
								<br /> 下面为某个类的示例代码<span lang="EN-US"><o:p></o:p></span></span>
				</b>
				<span style="font-family: 宋体;">
						<br /> <font size="4">(其中包含有一个<span lang="EN-US">message</span>属性，该类通过其<span lang="EN-US">setMessage()</span>方法获得右容器所提供的值。)</font></span>
		</p>
		<p class="MsoNormal" style="text-indent: 21pt;">
		</p>
		<p class="MsoNormal">
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> UpperAction  </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> Action<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String message;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> String getMessage() <br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> message;<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setMessage(String string) <br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    message </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> string;<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);"></span></div>
		<br />
		<span style="font-family: 宋体;">
		</span>
		<b style="">
				<span style="font-family: 宋体;" lang="EN-US"> </span>
		</b>
		<font size="3">
				<span style="font-family: 宋体;" lang="EN-US">
						<font color="#663300">其中message</font>
				</span>
		</font>
		<font color="#663300" size="3">
				<span style="font-family: 宋体;">
						属性的值通过配置文件来提供
				</span>
		</font>
		<p class="MsoNormal">
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="theUpperAction"</span><span style="color: rgb(255, 0, 0);">  class</span><span style="color: rgb(0, 0, 255);">="springj2seapp.UpperAction"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="message"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">HeLLo,UpperAction </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);"></span></div>
		<br />
		<span style="font-family: 宋体;">
		</span>
		<b style="">
				<span style="font-family: 宋体;">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</span>
		</b>
		<b style="">
				<span style="font-size: 10.5pt; font-family: 宋体;" lang="EN-US">Type3 </span>
				<span style="font-size: 10.5pt; font-family: 宋体;">构造子注入：</span>
		</b>
		<span style="font-size: 10.5pt; font-family: 宋体;">
				<font color="#660000">在<span lang="EN-US">Type3</span>类型的依赖注入机制中，依赖关系是通过类构造函数建立，容器通过调用类的构造方法，将其所需的依赖关系注入其中。</font>
				<br />
		</span>
		<b style="">
				<span style="font-size: 10.5pt; font-family: 宋体;">
						<br />示例代码：<br />配置文件如下<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="exampleBean"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="examples.ExampleBean"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="anotherExampleBean"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="yetAnotherBean"</span><span style="color: rgb(0, 0, 255);">/&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="int"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="anotherExampleBean"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="examples.AnotherBean"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="yetAnotherBean"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="examples.YetAnotherBean"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);"></span></div><br /><br /></span>
		</b>
		<b>
				<span style="font-size: 10.5pt; font-family: 宋体;">
						<span style="color: rgb(0, 0, 0);">ExampleBean代码：</span>
				</span>
		</b>
		<br />
		<b style="">
				<span style="font-size: 10.5pt; font-family: 宋体;">
						<br />
				</span>
		</b>
		<span style="font-size: 10.5pt; font-family: 宋体;">
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ExampleBean <br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> AnotherBean beanOne;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> YetAnotherBean beanTwo;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i;<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> ExampleBean(AnotherBean anotherBean, YetAnotherBean yetAnotherBean, <br />                                                                    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i) <br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.beanOne </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> anotherBean;<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.beanTwo </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> yetAnotherBean;<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> i;<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);"></span></div>
		</span>
		<span style="font-family: 宋体;">
				<br />
				<font color="#336600" size="4">当构造方法中带多个不同的基本数据类型的参数时，为了避免产生二义性，可以采用<span lang="EN-US">type</span>或者<span lang="EN-US">index</span>来指定构造方法的参数的类型和顺序。</font>
				<font size="4">
						<br />如：</font>
				<br />   <b>type方法</b><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="int"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">7500000</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg </span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="java.lang.String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">42</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">7</span> <span style="color: rgb(0, 0, 0);"></span></div><span lang="EN-US"><o:p></o:p></span></span>
		<br />
		<span style="font-size: 10.5pt; font-family: 宋体;">    <b><font color="#330000">index方法</font></b><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="exampleBean"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="examples.ExampleBean"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg </span><span style="color: rgb(255, 0, 0);">index</span><span style="color: rgb(0, 0, 255);">="0"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">7500000</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg </span><span style="color: rgb(255, 0, 0);">index</span><span style="color: rgb(0, 0, 255);">="1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">42</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">7</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">8</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">9</span> <span style="color: rgb(0, 0, 0);"></span></div><br /><font color="#663300"><b>总结：</b></font></span>
		<span style="font-size: 10.5pt; font-family: 宋体;">
				<br />     <font size="3"><b><font color="#003300">type1在灵活性、易用性上不如其他两种注入模式，</font></b></font></span>
		<b>
				<font color="#003300" size="4">
						<font size="3">
								<span style="font-size: 10.5pt; font-family: 宋体;" lang="EN-US">Type2</span>
								<span style="font-size: 10.5pt; font-family: 宋体;">和<span lang="EN-US">Type3</span>型的依赖注入实现则是目前主流的<span lang="EN-US">IOC</span>实现模式，</span>
								<span style="font-size: 10.5pt; font-family: 宋体;" lang="EN-US">Type3</span>
								<span style="font-size: 10.5pt; font-family: 宋体;">和<span lang="EN-US">Type2</span>模式各有千秋，而<span lang="EN-US">Spring</span>都对<span lang="EN-US">Type3</span>和<span lang="EN-US">Type2</span>类型的依赖注入机制提供了良好支持。</span>
								<span style="font-family: 宋体;">以<span lang="EN-US">Type3</span>类型为主，辅之以<span lang="EN-US">Type2</span>类型机制作为补充，可以达到最好的依赖注入效果，不过对于基于<span lang="EN-US">Spring
Framework</span>开发的应用而言，<span lang="EN-US">Type2</span>使用更加广泛。<span lang="EN-US"><o:p></o:p></span></span>
						</font>
				</font>
				<i>
						<font color="#003300" size="4">
						</font>
				</i>
		</b>
		<span style="font-size: 10.5pt; font-family: 宋体;">
				<br />
		</span>
		<p>
				<b style="">
						<span style="font-size: 10.5pt; font-family: 宋体;">
						</span>
				</b>
		</p>
<img src ="http://www.blogjava.net/improviser/aggbug/148472.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-26 23:59 <a href="http://www.blogjava.net/improviser/archive/2007/09/26/148472.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之六（IoC Singleton）</title><link>http://www.blogjava.net/improviser/archive/2007/09/26/148298.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Wed, 26 Sep 2007 05:22:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/26/148298.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/148298.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/26/148298.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/148298.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/148298.html</trackback:ping><description><![CDATA[
		<div align="justify">   <font color="#333300"><b style=""><font size="4">Spring中BeanFactory<span style="font-family: 宋体;">支持两个对象模型</span></font><span style="font-family: 宋体;"><span lang="EN-US"><o:p></o:p></span></span></b></font></div>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;" align="justify">
				<!--[if !supportLists]-->
				<font color="#333300">
						<span style="font-family: Wingdings;" lang="EN-US">
								<span style="">
										<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
										</span>
								</span>
						</span>
				</font>
				<!--[endif]-->
				<font color="#333300">
						<b>
								<span style="font-family: 宋体;">单态：</span>
						</b>
						<span style="font-family: 宋体;">
								<font size="4">模型提供了具有特定名称的对象的共享实例，可以在查询时对其进行检索。<span lang="EN-US">Singleton </span>是默认的也是最常用的对象模型。对于无状态   服务对象很理想。</font>
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;" align="justify">
				<!--[if !supportLists]-->
				<font color="#333300">
						<span style="font-family: Wingdings;" lang="EN-US">
								<span style="">
								</span>
						</span>
						<b>
								<span style="font-family: 宋体;">原型：</span>
								<font size="4">
								</font>
						</b>
						<font size="4">
								<span style="font-family: 宋体;">模型确保每次检索都会创建单独的对象。在每个用户都需要自己的对象时，原型模型最适合。</span>
						</font>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;" align="justify">
				<span style="font-family: 宋体;">
						<b>
								<font color="#333300" size="4">实例：</font>
								<font size="4">
								</font>
						</b>
						<br />
				</span>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">  beans  </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">      <br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> non-singleton examples </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="nonSingleton"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="java.lang.String"</span><span style="color: rgb(255, 0, 0);"> singleton</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">         </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">              </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Value</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">         </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">singleton：指定此JavaBean是否采用单例（Singleton）模式，如果设为"true"，则在BeanFactory作用范围内，只维护此JavaBean  的一个实例，代码通过BeanFactory   获得此JavaBean  实例的引用。反之，如果设为"false"，则通过BeanFactory获取此Java Bean  实例时，BeanFactory每次都将创建一个新的实例返回。</span></div>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">    </p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);">     1</span> <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> NonSingleton {<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"> <br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">BeanFactory factory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">build/beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">       <br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">   String s1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)factory.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">nonSingleton</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">   String s2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)factory.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">nonSingleton</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">   System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Identity Equal?: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> (s1 </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">s2));<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">   System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Value Equal:? </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> s1.equals(s2));<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">   System.out.println(s1);<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">   System.out.println(s2);<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);"> }<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">}</span></div>
		<p>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">   <i><b><font size="4"><font color="#003300">分析结果：</font></font></b></i></p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">   <font color="#009900">Identity Equal?: true<br />Value Equal:? true<br />Value<br />Value</font><br /></p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">   由结果可以看出由fantory产生的bean对象只有一个。<br /><span style="font-family: 宋体;"></span></p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">
				<span style="font-family: 宋体;">
						<br />
				</span>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">
		</p>
		<p class="MsoNormal" style="text-indent: 21pt;">
				<b>
						<span style="font-family: 宋体;"> <font color="#ff0000"> 注意</font>：</span>
				</b>
				<font size="4">
						<span style="font-family: 宋体;">
								<font color="#33cc00">在<span lang="EN-US">Spring</span>中消除了由用户自己来实现<span lang="EN-US">Singleton</span>模式的应用，<span lang="EN-US">Spring Bean</span>的缺省行为就是<span lang="EN-US">Singleton</span>，不必再为了<span lang="EN-US">Singleton</span>编码。</font>
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</span>
				</font>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">
				<br />
				<span style="font-family: 宋体;">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
<img src ="http://www.blogjava.net/improviser/aggbug/148298.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-26 13:22 <a href="http://www.blogjava.net/improviser/archive/2007/09/26/148298.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之五（Hierarchical Bean Factory Usage）</title><link>http://www.blogjava.net/improviser/archive/2007/09/25/147934.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Mon, 24 Sep 2007 16:05:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/25/147934.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/147934.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/25/147934.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/147934.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/147934.html</trackback:ping><description><![CDATA[
		<strong>
				<span style="font-size: 14pt;">
						<span style="color: rgb(24, 38, 255);">本文研究Spring分层Bean Factory用法，先看有关代码：</span>
				</span>
		</strong>
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="color: rgb(0, 128, 128);"> 1</span> parent<span style="color: rgb(0, 0, 0);">.xml<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <br />
      "http://www.springframework.org/dtd/spring-beans.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="injectBean"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="java.lang.String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">               </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Bean In Parent</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="injectBeanParent"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="java.lang.String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">               </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Bean In Parent</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  <br /></span></div>
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">beans.xml<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <br />
    "http://www.springframework.org/dtd/spring-beans.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> hierarchical bean factories </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="target1"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="SimpleTarget"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="val"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="injectBeanParent"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="target2"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="SimpleTarget"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="val"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">local</span><span style="color: rgb(0, 0, 255);">="injectBean"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="target3"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="SimpleTarget"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="val"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">parent</span><span style="color: rgb(0, 0, 255);">="injectBean"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="injectBean"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="java.lang.String"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">               </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Bean In Child</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">constructor-arg</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">30</span> </div>
		<br />
		<h1>
				<strong>
						<code>
								<font color="#000000">
										<span style="color: rgb(24, 38, 255);">SimpleTarget中只有一属性String val</span>
								</font>
						</code>
				</strong>
		</h1>
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">        BeanFactory parent </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">build/parent.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">        BeanFactory child </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">build/beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">), parent);<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">        SimpleTarget target1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (SimpleTarget) child.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">target1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">        SimpleTarget target2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (SimpleTarget) child.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">target2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        SimpleTarget target3 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (SimpleTarget) child.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">target3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">        System.out.println(target1.getVal());<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">        System.out.println(target2.getVal());<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">        System.out.println(target3.getVal());<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">    }</span></div>
		<br />
		<strong>
				<font size="4">
						<span style="color: rgb(24, 38, 255);">运行结果：</span>
				</font>
		</strong>
		<br />
		<span style="color: rgb(24, 38, 255);">
				<font size="4">Bean In Parent<br />
Bean In Child<br />
Bean In Parent</font>
				<br />
				<br />
				<font size="4">
						<b>
分析过程：</b>
				</font>
				<br />
				<font size="4">
在bean factory被加载过程中分别加载各层Bean Factory，</font>
		</span>
		<font size="4">
				<span style="color: rgb(0, 0, 0);">BeanFactory parent </span>
				<span style="color: rgb(0, 0, 0);">=</span> <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">build/parent.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /></span><span style="color: rgb(0, 0, 0);">BeanFactory child </span><span style="color: rgb(0, 0, 0);">=</span> <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">build/beans.xml</span><span style="color: rgb(0, 0, 0);">"</span></font>
		<span style="color: rgb(0, 0, 0);">
				<font size="4">), <span style="color: rgb(255, 0, 0);">parent</span>);<br /></font>
				<span style="color: rgb(24, 38, 255);">
						<font size="4">其中parent参数指定了bean factory间的父子关系。</font>
						<br />
						<br />
						<font size="4">
								<b>
分析结果：</b>
						</font>
						<br />
						<font size="4">
第一行结果为在父factory中定义的参数，说明在子fantory中可以直接调用父fantory元素，类似于java中的继承关系。<br />
第二行结果说明</font>
				</span>
		</span>
		<font size="4">
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">ref </span>
				<span style="color: rgb(255, 0, 0);">local</span>
				<span style="color: rgb(0, 0, 255);">="injectBean"</span>
				<span style="color: rgb(0, 0, 255);">/&gt;中local指向本fantory元素。<br />
第三行结果为Bean In Parent，说明</span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">ref </span>
				<span style="color: rgb(255, 0, 0);">parent</span>
				<span style="color: rgb(0, 0, 255);">="injectBean"</span>
				<span style="color: rgb(0, 0, 255);">/&gt;中parent指向父fantory中元素。</span>
		</font>
		<br />
		<br />
		<br />
		<br />
<img src ="http://www.blogjava.net/improviser/aggbug/147934.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-25 00:05 <a href="http://www.blogjava.net/improviser/archive/2007/09/25/147934.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之四（Spring Event）</title><link>http://www.blogjava.net/improviser/archive/2007/09/24/147914.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Mon, 24 Sep 2007 14:38:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/24/147914.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/147914.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/24/147914.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/147914.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/147914.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Spring中提供一些Aware相关的接口，BeanFactoryAware、 ApplicationContextAware、ResourceLoaderAware、ServletContextAware等等，其中最常用到的是ApplicationContextAware。实现ApplicationContextAware的Bean，在Bean被初始后，将会被注入 ApplicationContext的实例。ApplicationContextAware提供了publishEvent()方法，实现Observer(观察者)设计模式的事件传播机，提供了针对Bean的事件传播功能。通过Application.publishEvent方法，我们可以将事件通知系统内所有的ApplicationListener。&nbsp;&nbsp;<a href='http://www.blogjava.net/improviser/archive/2007/09/24/147914.html'>阅读全文</a><img src ="http://www.blogjava.net/improviser/aggbug/147914.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-24 22:38 <a href="http://www.blogjava.net/improviser/archive/2007/09/24/147914.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之三（Usage of property config）</title><link>http://www.blogjava.net/improviser/archive/2007/09/24/147777.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Mon, 24 Sep 2007 05:51:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/24/147777.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/147777.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/24/147777.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/147777.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/147777.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 本文内容演示属性文件用法的简单例子。<br>首先定义模型接口Model，视图接口View，以及它们实现类ImpModel，ImpView.<br>Model中定义方法getString();View中定义Model实例为其属性，在实现类ImpView中实现方法<br>disPlay(),其方法体为Model实例的getString()方法，并将其打印出来。&nbsp;&nbsp;<a href='http://www.blogjava.net/improviser/archive/2007/09/24/147777.html'>阅读全文</a><img src ="http://www.blogjava.net/improviser/aggbug/147777.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-24 13:51 <a href="http://www.blogjava.net/improviser/archive/2007/09/24/147777.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之二（Collection Injection）</title><link>http://www.blogjava.net/improviser/archive/2007/09/24/147710.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Mon, 24 Sep 2007 02:23:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/24/147710.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/147710.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/24/147710.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/147710.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/147710.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 通过<list/>,<set/>,<map/>以及<props/>元素定义和设置与java collection类型对应的List，Set，Map，Rproperties的值。&nbsp;&nbsp;<a href='http://www.blogjava.net/improviser/archive/2007/09/24/147710.html'>阅读全文</a><img src ="http://www.blogjava.net/improviser/aggbug/147710.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-24 10:23 <a href="http://www.blogjava.net/improviser/archive/2007/09/24/147710.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring笔记之一（初探Spring）</title><link>http://www.blogjava.net/improviser/archive/2007/09/24/147650.html</link><dc:creator>improviser</dc:creator><author>improviser</author><pubDate>Sun, 23 Sep 2007 17:31:00 GMT</pubDate><guid>http://www.blogjava.net/improviser/archive/2007/09/24/147650.html</guid><wfw:comment>http://www.blogjava.net/improviser/comments/147650.html</wfw:comment><comments>http://www.blogjava.net/improviser/archive/2007/09/24/147650.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/improviser/comments/commentRss/147650.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/improviser/services/trackbacks/147650.html</trackback:ping><description><![CDATA[   <font color="#333300" size="4"></font><span style="font-size: 10.5pt; font-family: 宋体;"><span style="font-family: Comic Sans MS;"><span style="font-family: Arial;"><span style="font-family: Comic Sans MS;"><span style="font-size: 12pt;"><span style="font-size: 18pt;"><span style="font-family: Verdana;"><span style="font-family: Comic Sans MS;"><span style="font-size: 10.5pt; font-family: 宋体;"><span><span style="font-size: 10.5pt; font-family: 宋体;"><span style="font-size: 24pt;"><span style="font-size: 14pt;"><span style="font-size: 10pt;"><span style="font-size: 10.5pt; font-family: 宋体;"><font color="#333300" size="4">初探Spring程序，程序如下：</font><br /><br />
     </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">BeanNaming.java<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> spring.beantest;<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.beans.factory.BeanFactory;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.beans.factory.xml.XmlBeanFactory;<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.core.io.FileSystemResource;<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> BeanNaming {<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String []args)<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    {<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">        BeanFactory factory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">src/applicationContext.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">        String s1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)factory.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">        String s2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)factory.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        String s3 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)factory.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">        String s4 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)factory.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name4</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">        System.out.println((s1 </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> s2));<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        System.out.println((s2 </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> s3));<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">        System.out.println((s3 </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> s4));<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">        String[] x </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> factory.getAliases(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(String str:x)<br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">        {<br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">            System.out.println(str);<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">      }<br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);"> <br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">      applicationContext.xml<br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">&lt;?</span><span style="color: rgb(0, 0, 0);">xml version</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> encoding</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF-8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">&lt;!</span><span style="color: rgb(0, 0, 0);">DOCTYPE beans PUBLIC </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">-//SPRING//DTD BEAN//EN</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://www.springframework.org/dtd/spring-beans.dtd</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">beans</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">&lt;!--</span><span style="color: rgb(0, 0, 0);"> aliasing examples </span><span style="color: rgb(0, 0, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">bean id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name2,name3,name4</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">java.lang.String</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">beans</span><span style="color: rgb(0, 0, 0);">&gt;</span></div><br />
    <font size="4"><span style="color: red;">输出结果为：</span><br /><span style="color: rgb(24, 125, 255);">
    true<br />
    true<br />
    true<br />
    name1<br />
    name4<br />
    name2</span></font><br />
    <br />
    <font size="4"><span style="color: rgb(74, 48, 255);">可以看出，使用中id属性和name属性几乎没有任何区别。调用beanfactory.getAliases(string)的方法时，传入的参数可以是任意一个bean名字，输出的别名则是除去作为参数本身之外的所有
bean名。</span><br />
   <br /><br />
   <span style="color: rgb(24, 38, 255);">另</span>：<span style="color: rgb(74, 48, 255);">在写
applicationContxt.xml文件时，如果没有定义&lt;!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"&gt;，则会抛出</span><span style="color: red;"><span style="color: rgb(14, 0, 0);"><span style="color: red;">Cannot find the declaration of element 'beans'</span></span></span><span style="color: rgb(74, 48, 255);">异常。</span></font><br />
  
<br />
      <strong><font size="4"><span style="color: rgb(107, 40, 255);">以上使用BeanFactory对配置文件进行加载，BeanFactory，是根据配置文件负责创建Bean的实例，并负责Bean的生命周期的管理-
--，包括Bean的生成与销毁、Bean的创建方式的识别（是否为singleton）、Bean的各个属性的设定、依赖关系的建立等。<br />
   
ApplicationContext接口，提供了国际化、事件处理及beans在context中的自查能力。它也可创建具有层次结构context环
境，将bean的作用域和可访问区域限制在应用程序的一个特定部分中。下面演示如何使用ApplicationContext接口。</span></font><br /></strong><br />
    <br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">&lt;!</span><span style="color: rgb(0, 0, 0);">DOCTYPE beans PUBLIC </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">-//SPRING//DTD BEAN//EN</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://www.springframework.org/dtd/spring-    beans.dtd</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">beans</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">bean id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bean_1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">BeanTest</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">bean id</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bean_2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">BeanTest</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">beans</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> BeanTest {<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> test() {<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test..</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">   }<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.ApplicationContext;<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.support.FileSystemXmlApplicationContext;<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> BeanNameExample {<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        ApplicationContext ctx </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemXmlApplicationContext(<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">build/applicationContext.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">        BeanTest beanOne </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (BeanTest)ctx.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bean_1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">        BeanTest beanTwo </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (BeanTest)ctx.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bean_2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">        beanOne.test();<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">        beanTwo.test();<br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">      }<br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">   }<br /></span><span style="color: rgb(0, 128, 128);">31</span> </div>
  <font size="4"><span style="color: rgb(107, 40, 255);"><strong>综上，ApplicationContext与BeanFactory的不同点<br />
  
BeanFactory提供了针对JavaBean的管理功能，而ApplicationContext提供了一个更为框架化的实现（从上面的示例中可以
看出，BeanFactory的使用方式更加类似一个API，而非Framework
style）。ApplicationContext覆盖了BeanFactory的所有功能，并提供了更多的特性。此外，
ApplicationContext为与现有应用框架相整合，提供了更为开放式的实现（如对于Web应用，我们可以在web.xml中对
ApplicationContext进行配置）。</strong></span></font><strong></strong><img src ="http://www.blogjava.net/improviser/aggbug/147650.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/improviser/" target="_blank">improviser</a> 2007-09-24 01:31 <a href="http://www.blogjava.net/improviser/archive/2007/09/24/147650.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>