zoukankan      html  css  js  c++  java
  • Spring.Net 配置文件

    方法一. 直接在程序配置文件中配置

     1 <configuration>
     2 
     3   <configSections>
     4     <sectionGroup name="spring"> 
     5       <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
     6       <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
     7     </sectionGroup>
     8   </configSections>
     9 
    10   <spring>
    11     <context>
    12       <resource uri="config://spring/objects"/>
    13     </context>
    14     <objects xmlns="http://www.springframework.net">      
    15       <object id="Person" type="PhoneNumberWhere.Person, PhoneNumberWhere">  //类的全名称,程序集名称
    16         <property name="Name" value="MyName"/>     //简单属性配置,key-value
    17         <property name="SonMan" ref="Son"/>      //复杂属性配置,ref
    18       </object>
    19       <object id="Son" type="PhoneNumberWhere.Son, PhoneNumberWhere">   //
    20       </object>
    21     </objects>
    22   </spring>
    23 
    24 </configuration>

     方法二. 引用外部xml文件配置

    <?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"/>
          <resource uri="file://objs.xml"/>  //引用xml文件,并把xml设置为【始终复制】嵌入的资源
        </context>
        <objects xmlns="http://www.springframework.net">      
        </objects>
      </spring>
    </configuration>

    objs.xml文件

    <?xml version="1.0" encoding="utf-8" ?>
    <objects xmlns="http://www.springframework.net">
      <object id="Person" type="PhoneNumberWhere.Person, PhoneNumberWhere">
        <property name="Name" value="MyName"/>
        <property name="SonMan" ref="Son"/>
      </object>
      <object id="Son" type="PhoneNumberWhere.Son, PhoneNumberWhere">
        <constructor-arg index="0" value="son.txt"/>
      </object>
    </objects>

    创建对象【引用  Spring.Core.dlll   Common.Logging.dll】

    IApplicationContext ctx = ContextRegistry.GetContext();
    Person person = (Person)ctx.GetObject("Person");

  • 相关阅读:
    二叉查找树
    Hash算法原理理解
    算法的时间复杂度
    解决Ubuntu14.04下Clementine音乐播放器不能播放wma文件的问题
    Ubuntu 14.04 开启启动器图标最小化功能
    Ubuntu14.04建立WiFi热点
    C语言运算符优先级
    老鸟的Python入门教程
    MD5算法步骤详解
    MD5算法
  • 原文地址:https://www.cnblogs.com/yougmi/p/4545514.html
Copyright © 2011-2022 走看看