使用Spring的最小好处

来源:互联网 发布:孕妇装春装2015淘宝网 编辑:程序博客网 时间:2024/04/29 01:53
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

现在自己是PM了(虽然手下只有自己一个人)向老板要了几周时间开始重构一个虽然质量上只能说是DEMO但却已经搭配其他软件卖给用户了的破程序。嗨,想当年可是连续2个月,天天10点以后才回家,熬出来的东东呀。

言归正传,最先引入Spring,只是看中它和hebernate集成的很好,web层又比struts简化得多。不过这几天还在重构逻辑层的代码,发现了他的一个可能非常微小的好处——读取配置文件。原先的配置文件是XML格式,各个模块的所有配置都写在里面,由一个singleton的Config类解析,提供访问。造成所有的模块都依赖于Config类,影响了代码的复用。现在用了Spring,所有的类需要配置信息的话只要提供Set方法,统一配置在Spring的context中,Spring会帮你解析配置,转化为你所需要的类型,然后set给你的类,而且还支持多个配置文件,refresh。

呵呵,IOC还是有些好处的,吾将上下而求索。

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>