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");

  • 相关阅读:
    被隐藏的文件更改为可见
    Selenium WebDriver多层表单切换
    for循环
    Java课程设计二次大作业
    Java-DAO模式代码阅读及应用
    编辑器、编译器、文件、IDE等常见概念辨析
    树、二叉树和查找等知识点的总结
    二叉树的实现
    二叉树顺序结构和链式结构的相互转换
    使用k-近邻算法改进约会网站的配对效果
  • 原文地址:https://www.cnblogs.com/yougmi/p/4545514.html
Copyright © 2011-2022 走看看