此外,还需要在Config文件中进行配置,配置如下:<?xml version="1.0" encoding="utf-8" ?><configuration>
<configSections> <sectionGroup name="spring"> <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/> <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> </sectionGroup> </configSections> <spring> <context> <resource uri="config://spring/objects"/> </context> <objects xmlns="http://www.springframework.net" > <description></description> <object name="Business" type="IOCExample.Business, IOCExample"> <property name="Logger"> <ref object="AnLog" /> </property> </object> <object name="AnLog" type="IOCExample.Log, IOCExample"> </object> </objects> </spring> </configuration>关键在于objects 结点的定义,其中定义了类与类之间的依赖关系。 通过这个例子可以看出,使用IOC的意义在于将两个类之间的关联放到了配置文件之中(而并非删除这种关联),其类图如图2.
posted on 2005-07-19 11:04 wljcan 阅读(1296) 评论(0) 编辑 收藏