﻿<?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/zhaijianhui/category/11283.html</link><description>研究java技术</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 14:47:38 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 14:47:38 GMT</pubDate><ttl>60</ttl><item><title>spring集成到web框架</title><link>http://www.blogjava.net/zhaijianhui/archive/2006/08/02/61423.html</link><dc:creator>蜘蛛</dc:creator><author>蜘蛛</author><pubDate>Wed, 02 Aug 2006 15:41:00 GMT</pubDate><guid>http://www.blogjava.net/zhaijianhui/archive/2006/08/02/61423.html</guid><wfw:comment>http://www.blogjava.net/zhaijianhui/comments/61423.html</wfw:comment><comments>http://www.blogjava.net/zhaijianhui/archive/2006/08/02/61423.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaijianhui/comments/commentRss/61423.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaijianhui/services/trackbacks/61423.html</trackback:ping><description><![CDATA[
		<p>把spring集成到web框架很简单，只要在web.xml里面加上<br />&lt;context-param&gt;<br />    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br />    &lt;param-value&gt;/WEB-INF/applicationContext*.xml&lt;/param-value&gt;<br />&lt;/context-param&gt;<br />或者<br />&lt;listener&gt;<br />    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;<br />&lt;/listener&gt;<br />如果为下面这种方式的话，那么就是加载默认的文件<br /><em><span class="emphasis">/WEB-INF/applicationContext.xml<br /></span>这个在<br /></em>org.springframework.web.context.support.XmlWebApplicationContext类里面定义的,,部分代码：<br />/** Default config location for the root context */<br /> public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml";</p>
		<p> /** Default prefix for building a config location for a namespace */<br /> public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/";</p>
		<p> /** Default suffix for building a config location for a namespace */<br /> public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml";<br /><br /><br />Once the context files are loaded, Spring creates a <a href="http://www.springframework.org/docs/api/org/springframework/web/context/WebApplicationContext.html" target="_top"><tt class="literal"><font color="#002c99">WebApplicationContext</font></tt></a> object based on the bean definitions and puts it into the <tt class="literal">ServletContext</tt>.<br />这样我们就可以直接用ServletContext获取自己想要的参数的，，<br /></p>
		<p>All Java web frameworks are built on top of the Servlet API, so you can use the following code to get the <tt class="literal">ApplicationContext</tt> that Spring created.</p>
		<pre class="programlisting">WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);</pre>
		<p>通过WebApplicationContext我们就可以通过bean的名字获取它的实例了<br />The <a href="http://www.springframework.org/docs/api/org/springframework/web/context/support/WebApplicationContextUtils.html" target="_top"><tt class="literal"><font color="#002c99">WebApplicationContextUtils</font></tt></a> class is for convenience, so you don't have to remember the name of the <tt class="literal">ServletContext</tt> attribute. Its <span class="emphasis"><em>getWebApplicationContext()</em></span> method will return null if an object doesn't exist under the <tt class="literal">WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE</tt> key. Rather than risk getting NullPointerExceptions in your application, it's better to use the <span class="emphasis"><em>getRequiredWebApplicationContext()</em></span> method. This method throws an Exception when the <span class="emphasis"><em>ApplicationContext</em></span> is missing.</p>
		<p>Once you have a reference to the <tt class="literal">WebApplicationContext</tt>, you can retrieve beans by their name or type. Most developers retrieve beans by name, then cast them to one of their implemented interfaces.</p>
		<p>Fortunately, most of the frameworks in this section have simpler ways of looking up beans. Not only do they make it easy to get beans from the <tt class="literal">BeanFactory</tt>, but they also allow you to use dependency injection on their controllers. Each framework section has more detail on its specific integration strategies.</p>
<img src ="http://www.blogjava.net/zhaijianhui/aggbug/61423.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaijianhui/" target="_blank">蜘蛛</a> 2006-08-02 23:41 <a href="http://www.blogjava.net/zhaijianhui/archive/2006/08/02/61423.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>读取配置文件的几种方法</title><link>http://www.blogjava.net/zhaijianhui/archive/2006/06/03/50104.html</link><dc:creator>蜘蛛</dc:creator><author>蜘蛛</author><pubDate>Sat, 03 Jun 2006 03:24:00 GMT</pubDate><guid>http://www.blogjava.net/zhaijianhui/archive/2006/06/03/50104.html</guid><wfw:comment>http://www.blogjava.net/zhaijianhui/comments/50104.html</wfw:comment><comments>http://www.blogjava.net/zhaijianhui/archive/2006/06/03/50104.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaijianhui/comments/commentRss/50104.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaijianhui/services/trackbacks/50104.html</trackback:ping><description><![CDATA[在读spring in aciton 时，他用的BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));<br />可是现在的用的1.2.6版本的构造器(XmlBeanFactory)只能接收Resource接口了，所以调不出来是正常的事情，假设现在有一个文件hello.xml<br />读取方法<br /><br />1:ApplicationContext cx=new FileSystemXmlApplicationContext("hello.xml");//指定的路径去找文件<br />2:ApplicationContext factory = new ClassPathXmlApplicationContext("hello.xml");//还会在classpath去找<br />3:Resource fa = new FileSystemResource("hello.xml");<br />   BeanFactory factory=new XmlBeanFactory(fa);<br />4:这个要设制classpath了，麻烦<br />　 Resource res = new ClassPathResource("com/springinaction/chapter01/hello/hello.xml");<br />　 BeanFactory factory=new XmlBeanFactory(res);<br />好了，用了上面那种方法都可以调用getBean("your bean name")了，<br />eg: BeanFactory factory=new XmlBeanFactory(fa);<br />      hello he=(hello)factory.getBean("hello");<br />              he.getHello();<img src ="http://www.blogjava.net/zhaijianhui/aggbug/50104.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaijianhui/" target="_blank">蜘蛛</a> 2006-06-03 11:24 <a href="http://www.blogjava.net/zhaijianhui/archive/2006/06/03/50104.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring入门与实践</title><link>http://www.blogjava.net/zhaijianhui/archive/2006/06/01/49380.html</link><dc:creator>蜘蛛</dc:creator><author>蜘蛛</author><pubDate>Wed, 31 May 2006 17:37:00 GMT</pubDate><guid>http://www.blogjava.net/zhaijianhui/archive/2006/06/01/49380.html</guid><wfw:comment>http://www.blogjava.net/zhaijianhui/comments/49380.html</wfw:comment><comments>http://www.blogjava.net/zhaijianhui/archive/2006/06/01/49380.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaijianhui/comments/commentRss/49380.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaijianhui/services/trackbacks/49380.html</trackback:ping><description><![CDATA[为他方便大家更快的学习Spring，特整理了第一个实例，<br />做成了pdf格式,还附带源代码，欢迎下载<br />开发平台<br />myeclipse 4.1.1GA<br />eclipse 3.1.2<br />你也可以选择其它开发工具,并不影响你阅读此教程.<a href="/Files/zhaijianhui/spring"><br />http://www.blogjava.net/Files/zhaijianhui/spring</a>入门.rar<img src ="http://www.blogjava.net/zhaijianhui/aggbug/49380.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaijianhui/" target="_blank">蜘蛛</a> 2006-06-01 01:37 <a href="http://www.blogjava.net/zhaijianhui/archive/2006/06/01/49380.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>