Spring框架的配置文件

							<h2 id="t_6f7265cf0102v9qx" class="titName SG_txta">Spring框架的配置文件</h2>
		
				<span class="img2">
			<img width="15" height="15" align="absmiddle" title="此博文包含图片" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" class="SG_icon SG_icon18">	
		</span>
				<span class="time SG_txtc">(2014-12-18 20:43:42)</span><div class="turnBoxzz"><a href="javascript:;" class="SG_aBtn SG_aBtn_ico SG_turn" action-type="reblog" action-data="{srcBlog:1, blogId:'6f7265cf0102v9qx'}"><cite><img class="SG_icon SG_icon111" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="15" height="15" align="absmiddle">转载<em class="arrow">▼</em></cite></a></div>		</div>
	<div class="articalTag" id="sina_keyword_ad_area">
		<table>
			<tbody><tr>
				<td class="blog_tag">
				<script>
				var $tag='配置文件,例子,构造函数,成员,spring';
				var $tag_code='04d1d4ab55d610fd8c461916aa470d54';
				var $r_quote_bligid='6f7265cf0102v9qx';
				var $worldcup='0';
				var $worldcupball='0';
				</script>
										<span class="SG_txtb">标签:</span>
																			<h3><a href="http://search.sina.com.cn/?c=blog&amp;q=%C5%E4%D6%C3%CE%C4%BC%FE&amp;by=tag" target="_blank">配置文件</a></h3>
																			<h3><a href="http://search.sina.com.cn/?c=blog&amp;q=%C0%FD%D7%D3&amp;by=tag" target="_blank">例子</a></h3>
																			<h3><a href="http://search.sina.com.cn/?c=blog&amp;q=%B9%B9%D4%EC%BA%AF%CA%FD&amp;by=tag" target="_blank">构造函数</a></h3>
																			<h3><a href="http://search.sina.com.cn/?c=blog&amp;q=%B3%C9%D4%B1&amp;by=tag" target="_blank">成员</a></h3>
																			<h3><a href="http://search.sina.com.cn/?c=blog&amp;q=spring&amp;by=tag" target="_blank">spring</a></h3>
															</td>
				<td class="blog_class">
										<span class="SG_txtb">分类:</span>
					<a target="_blank" href="http://blog.sina.com.cn/s/articlelist_1869768143_4_1.html">专业知识</a>
									</td>
			</tr>
		</tbody></table>
	</div>
					<!-- 正文开始 -->
	<div id="sina_keyword_ad_area2" class="articalContent   newfont_family">
		<p><span style="FonT-siZe: 10.5pt; FonT-FAMiLY: '微软雅黑',sans-serif">(注:文中的“《”均需替换为左尖括号,“》”均需替换为右尖括号)<span><br>

classpath下建立applicationContext.xml文件表示Spring框架的配置文件

1.import

可以导入其它的xml配置文件

例子:
import
resource="applicationConfig.xml" /


2.context:property-placeholder
扫描参数配置文件
例子:
context:property-placeholder location="classpath:database.properties" ignore-unresolvable="true"/
database.properties
中的文件内容:
# Redis settings
redis.host=127.0.0.1
xml中引用方式为:${redis.host}

 

3.context:component-scan

Spring扫描注解标签的范围

例子:

Spring框架的配置文件




4.tx:annotation-driven
启用对事务注解的支持
例子:
bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"

 property name="dataSource"
ref="dataSource"
/

/bean
tx:annotation-driven
transaction-manager="transactionManager" /


5.bean

spring 容器初始化
bean 和销毁前所做的操作配置(init-method="bind"
destroy-method="unbind"

5.1无任何设置
例子:
bean id="springContextUtil" class="com.deepai.common.util.SpringContextUtil" /


5.2设置数据成员(需要注入的属性必须有setter方法!!)

5.2.1设置普通数据成员值

例子:
bean
class="org.mybatis.spring.mapper.MapperScannerConfigurer"

 !--basePackage指定要扫描的包,在此包之下的映射器都会被搜索到。可指定多个包,包与包之间用逗号或分号分隔
--

 
property name="basePackage"
value="com.deepai.rudder.dao,com.deepai.authority.dao"
/

/bean

5.2.2
设置对象数据成员值

例子:
bean
class="org.springframework.beans.factory.config.CustomEditorConfigurer"

 property
name="customEditors"


  
entry
key="java.net.SocketAddress"
value="org.apache.mina.integration.beans.InetSocketAddressEditor"

  /entry

 /property
/bean

5.2.3设置对象数据成员的引用

bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"

 property name="dataSource"
ref="dataSource"
/

/bean

5.2.4
设置Map数据成员值

bean
class="org.springframework.beans.factory.config.CustomEditorConfigurer"

 property
name="customEditors"


  
map

   entry
key="java.net.SocketAddress"
value="org.apache.mina.integration.beans.InetSocketAddressEditor"

   /entry

  /map

 /property
/bean

5.2.5设置List数据成员值

bean id="shardedJedisPool"
class="redis.clients.jedis.ShardedJedisPool"
scope="singleton"


 
property
name="shards"


  
list

   bean
class="redis.clients.jedis.JedisShardInfo"


    
constructor-arg
name="host" value="${redis.host}" /


    
constructor-arg
name="port" value="${redis.port}" /


   
/bean

  /list

 /constructor-arg

/bean


5.3设置构造函数

5.3.1设置普通构造函数

bean
id="executorFilter"
class="org.apache.mina.filter.executor.ExecutorFilter"

 constructor-arg index="0" value="5"
/


 
constructor-arg index="1"
value="10"
/

/bean

5.3.2
设置有对象的构造函数

bean id="protocolCodecFilter"
class="org.apache.mina.filter.codec.ProtocolCodecFilter"

 constructor-arg

  
bean
class="org.apache.mina.filter.codec.textline.TextLineCodecFactory"
/


 
/constructor-arg

/bean


5.4工厂注入

package model.factory;

import model.Book;

public class BookFactory {

 public Book createJavaBook(){

  return new
Book("www","www","www", 0.0f);

 }

 public static Book create(){

  return new
Book("www","www","www", 0.0f);

 }

}

5.4.1非静态工厂

bean
id="bookFactory" class="model.factory.BookFactory"
/

bean id="myBook2"
factory-bean="bookFactory" factory-method="createJavaBook"
/

得到的是Book对象

5.4.2
静态工厂

bean id="myBook3" class="model.factory.BookFactory"
factory-method="create"
/
,
得到的是Book对象

 

0

0

        </div>
        <div class="clearit"></div>
	</div>
	<div class="articalInfo">
		<!-- 分享到微博 {$t_blog} -->
		<div class="IL">
			阅读<span id="r_6f7265cf0102v9qx" class="SG_txtb">(71)</span><em class="SG_txtb">┊</em> 
			<a href="#commonComment">评论</a> <span id="c_6f7265cf0102v9qx" class="SG_txtb">(0)</span><em class="SG_txtb">┊</em>				<a href="javascript:;" onclick="$articleManage('6f7265cf0102v9qx',5);return false;">收藏</a><span id="f_6f7265cf0102v9qx" class="SG_txtb">(0)</span>
			<em class="SG_txtb">┊</em><a href="#" id="quote_set_sign" onclick="return false ;">转载</a><a href="#" id="z_6f7265cf0102v9qx" onclick="return false ;" class="zznum">(0)</a>				<span id="fn_Spring框架的配置文件" class="SG_txtb"></span><em class="SG_txtb">┊</em>
			<a onclick="return false;" href="javascript:;"><cite id="d1_digg_6f7265cf0102v9qx">喜欢</cite></a><a id="d1_digg_down_6f7265cf0102v9qx" href="javascript:;"><b>▼</b></a>
								<em class="SG_txtb">┊</em><a href="http://blog.sina.com.cn/main_v5/ria/print.html?blog_id=blog_6f7265cf0102v9qx" target="_blank">打印</a><em class="SG_txtb">┊</em><a id="q_6f7265cf0102v9qx" onclick="report('6f7265cf0102v9qx');return false;" href="#">举报</a>
										</div>
		<div class="IR">
			<table>
				<tbody><tr>
										<th class="SG_txtb" scope="row">已投稿到:</th>
					<td>
						<div class="IR_list">
							<span><img class="SG_icon SG_icon36" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="15" height="15" title="排行榜" align="absmiddle"> <a href="http://blog.sina.com.cn/lm/114/117/day.html" class="SG_linkb" target="_blank">排行榜</a></span>							</div>
					</td>
									</tr>
								</tbody></table>
		</div>
	</div>
	<div class="clearit"></div>
	<div class="blogzz_zzlist borderc" id="blog_quote" style="display:none"><h3><a href="#" onclick="return false" title="关闭" id="ql_close6f7265cf0102v9qx" class="blogzz_closepic SG_floatR"></a>转载列表:</h3>                <ul class="ul_zzlist" id="ql_content6f7265cf0102v9qx">                </ul>				<ul style="display:none"><li id="ql_tip6f7265cf0102v9qx"></li></ul>                <div class="SG_clearB"></div>                <div class="blogzz_btn">					<a id="btnArticleQuote6f7265cf0102v9qx" href="#" onclick="scope.article_quote &amp;&amp; scope.article_quote.check('6f7265cf0102v9qx');return false;" class="SG_aBtn SG_aBtn_ico SG_turn"><cite><img class="SG_icon SG_icon111" id="quoteList_quote6f7265cf0102v9qx" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="15" height="15" align="absmiddle">转载</cite></a>					<p id="quoteDescription6f7265cf0102v9qx" class="SG_turntxt" style="display: none;">转载是分享博文的一种常用方式...</p>				</div>				<div id="ql_page6f7265cf0102v9qx" class="blogzz_paged"></div>				<div class="clearit"></div></div>
	<div class="articalfrontback SG_j_linedot1 clearfix" id="new_nextprev_6f7265cf0102v9qx">
						<div><span class="SG_txtb">前一篇:</span><a href="http://blog.sina.com.cn/s/blog_6f7265cf0102v9qs.html">控制反转IoC</a></div>
									<div><span class="SG_txtb">后一篇:</span><a href="http://blog.sina.com.cn/s/blog_6f7265cf0102v9rc.html">Spring&nbsp;MVC的配置文件</a></div>
				</div>
	<div class="clearit"></div>
						
	<div id="loginFollow"></div>
			<div class="allComm">
		<div class="allCommTit">
			<div class="SG_floatL">
			    <strong>评论</strong>
			    <span id="commAd_1" style="display: inline-block;">
			        <span style="margin-left:15px; width:220px; display:inline-block;"><a target="_blank" href="http://blog.sina.com.cn/lm/8/2009/0325/105340.html">重要提示:警惕虚假中奖信息</a></span>
			    </span>
			</div>
			<div class="SG_floatR"><a class="CP_a_fuc" href="#post">[<cite>发评论</cite>]</a></div>
		</div>
		<ul id="article_comment_list" class="SG_cmp_revert"><li><div class="noCommdate"><span class="SG_txtb">做第一个评论者吧! <img class="SG_icon SG_icon134" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="18" height="18" title="" align="absmiddle"><a href="#post">抢沙发&gt;&gt;</a></span></div></li></ul>
		<div class="clearit"></div>
		<div class="myCommPages SG_j_linedot1">
			<div class="SG_page" id="commentPaging" style="display:none;">
				<ul class="SG_pages">
				</ul>
			</div>
			<div class="clearit"></div>
		</div>
		<a name="post"></a>
		<div class="writeComm">
			<div class="allCommTit">
				<div class="SG_floatL">
				    <strong>发评论</strong>
				    <span></span>
				</div>
				<div class="SG_floatR"></div>
			</div>
			<div class="wrCommTit">
				<div class="SG_floatL" id="commentNick" style="display:none;"></div>
			</div>
			<div class="formTextarea">
				<div style="float:left;" id="commonComment">
				<iframe id="postCommentIframe" frameborder="0" style="border:1px solid #C7C7C7;
	height:158px;width:448px;maring-top:1px;background-color:white;" src="http://blog.sina.com.cn/main_v5/ria/blank2.html"></iframe>
				<textarea id="commentArea" tabindex="1" style="display:none;"></textarea>
				</div>
				<div id="mobileComment" style="float:left;display:none;">
					<textarea id="mbCommentTa" style="width:438px;height:150px;border:1px solid #C7C7C7;line-height:18px;padding:5px;"></textarea>
				</div>
				<div class="faceblk" id="faceWrap">
					<div id="smilesSortShow" class="faceline1">
					<div class="facestyle" id="recomm_1483863741903"><a href="#" key="302"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/302-25.gif" alt="小新小浪" title="小新小浪"></a><a href="#" key="308"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/308-25.gif" alt="炮炮兵" title="炮炮兵"></a><a href="#" key="315"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/315-25.gif" alt="张富贵" title="张富贵"></a><a href="#" key="316"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/316-25.gif" alt="旺狗" title="旺狗"></a><a href="#" key="331"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/331-25.gif" alt="悠嘻猴" title="悠嘻猴"></a><a href="#" key="351"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/351-25.gif" alt="酷巴熊" title="酷巴熊"></a></div><span class="SG_more"><a href="#">更多&gt;&gt;</a></span><div class="clearit"></div></div>
					<ul id="smilesRecommended" class="faceline01"><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0321EN00SIGT.gif" alt="就不买你" title="就不买你" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0320EN00SIGT.gif" alt="股市" title="股市" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0319EN00SIGT.gif" alt="发霉" title="发霉" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0318EN00SIGT.gif" alt="陈水边" title="陈水边" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0317EN00SIGT.gif" alt="裁员" title="裁员" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0316EN00SIGT.gif" alt="音乐" title="音乐" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0315EN00SIGT.gif" alt="贴你" title="贴你" height="50" width="50"></a></li><li><a href="#"><img src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___0314EN00SIGT.gif" alt="抢车位" title="抢车位" height="50" width="50"></a></li></ul>
				</div>
				<div class="clearit"></div>
			</div>
			<div class="formLogin">
				<div class="SG_floatL"> 
				<p id="commentlogin" style="display: block;"><span>登录名:</span><input type="text" style="width: 115px;" id="login_name" tabindex="2">   <span>密码:</span><input type="password" style="width: 115px;" id="login_pass" tabindex="3">   <a href="http://login.sina.com.cn/getpass.html" target="_blank">找回密码</a>   <a href="http://login.sina.com.cn/signup/signup.php?entry=blog&amp;src=blogicp&amp;srcuid=1869768143" target="_blank">注册</a>	<input type="checkbox" id="login_remember"><label for="login_remember" style="display:inline-block;" title="建议在网吧/公用电脑上取消该选项">记住登录状态</label></p><p id="commentloginM" style="display:none;"><span>昵&nbsp;&nbsp;&nbsp;称:</span><input type="text" style="width: 115px;" id="comment_anonyous" value="新浪网友" tabindex="2" disabled=""></p><p id="quote_comment_p"><input type="checkbox" id="bb"> <label for="bb"><img height="18" align="absmiddle" width="18" title="" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" class="SG_icon SG_icon110">分享到微博 <img height="15" align="absmiddle" width="15" title="新" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" class="SG_icon SG_icon11"></label>&nbsp;&nbsp;&nbsp;<input type="checkbox" id="cbCommentQuote"><label for="cbCommentQuote">评论并转载此博文</label><img class="SG_icon SG_icon11" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="15" height="15" title="新" align="absmiddle"></p>
				<p id="geetest-box"><div id="geetest_1483863753080" class="gt_holder float" style="touch-action: none;"><div class="gt_input"><input class="geetest_challenge" type="hidden" name="geetest_challenge"><input class="geetest_validate" type="hidden" name="geetest_validate"><input class="geetest_seccode" type="hidden" name="geetest_seccode"></div><div class="gt_slider"><div class="gt_guide_tip gt_show">按住左边滑块,拖动完成上方拼图</div><div class="gt_slider_knob gt_show" style="left: 0px;"></div><div class="gt_curtain_tip gt_hide">点击上图按钮并沿道路拖动到终点处</div><div class="gt_curtain_knob gt_hide">移动到此开始验证</div><div class="gt_ajax_tip ready"></div></div></div></p>
				</div>

				<span style="display: none; color: rgb(153, 153, 153); margin-left: 10px;" id="login_remember_caution"></span>

										<div class="SG_floatR" id="anonymity_cont" style="display: none;"><input type="checkbox" id="anonymity"><label for="anonymity">匿名评论</label></div>
								</div>
			<div class="formBtn">
				<a href="javascript:;" onclick="return false;" class="SG_aBtn" tabindex="5"><cite id="postcommentid">发评论</cite></a>
				<p class="SG_txtc">以上网友发言只代表其个人观点,不代表新浪网的观点或立场。</p>
			</div>
		</div>
	</div>
			<div class="clearit"></div>
	
			<div class="articalfrontback articalfrontback2 clearfix">
					  <div class="SG_floatL"><span class="SG_txtb">&lt;&nbsp;前一篇</span><a href="http://blog.sina.com.cn/s/blog_6f7265cf0102v9qs.html">控制反转IoC</a></div>
								  <div class="SG_floatR"><span class="SG_txtb">后一篇&nbsp;&gt;</span><a href="http://blog.sina.com.cn/s/blog_6f7265cf0102v9rc.html">Spring&nbsp;MVC的配置文件</a></div>
				</div>
	<div class="clearit"></div>
			
</div>
posted @ 2017-01-08 16:25  jobs-lgy  阅读(445)  评论(0编辑  收藏  举报