zoukankan      html  css  js  c++  java
  • 如何配置Spring的XML文件及使用

    App.config

     1 <?xml version="1.0" encoding="utf-8" ?>
     2 <configuration>
     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     <spring>
    10         <context>
    11             <!--<resource uri="config://spring/objects" />-->
    12             <resource uri="file://Spring_bean.xml" />
    13         </context>
    14         <!--<objects xmlns="http://www.springframework.net" >
    15       <object id="UserDao" type="SpringSample.UserDao, SpringSample"/>
    16       <object id="UserService" type="SpringSample.UserService, SpringSample" >
    17         <property name="UserDao" ref="UserDao"/>
    18       </object>
    19     </objects>-->
    20     </spring>
    21 </configuration>

    Spring_bean.xml

    1 <?xml version="1.0" encoding="utf-8" ?>
    2 <objects xmlns="http://www.springframework.net" >
    3     <object id="UserDao" type="SpringSample.UserDao, SpringSample"/>
    4     <object id="UserService" type="SpringSample.UserService, SpringSample" >
    5         <property name="UserDao" ref="UserDao"/>
    6     </object>
    7 </objects>

    Program

    1             IApplicationContext ctx = ContextRegistry.GetContext();
    2             IUserService userService = ctx.GetObject("UserService") as IUserService;
    3             Console.WriteLine(userService.GetName());
  • 相关阅读:
    Go 数组与切片
    Go 常用函数
    Go 函数,包(二)
    函数,包及错误处理
    Go 循环控制
    Go 流程控制
    Go 获取键盘输入,进制转换
    Go 指针,标识符命名规范及关键字
    Go 变量及基本数据类型3
    一文详解微服务架构
  • 原文地址:https://www.cnblogs.com/mybky/p/3811237.html
Copyright © 2011-2022 走看看